• Resolved fitnesspreponline

    (@fitnesspreponline)


    Hi, I am trying to do a calculations using a Calculated Field after pressing the calculate button. Here is what I have so far:
    (function(){
    var cal = 0;
    IF(fieldname5==1) return (cal = (10*(fieldname8*0.454)+6.25*(((fieldname6*12)+fieldname7)*2.54)-5*fieldname2+5) );
    IF(fieldname5==2) return (cal = (10*(fieldname8*0.454)+6.25*(((fieldname6*12)+fieldname7)*2.54)-5*fieldname2-161) );
    })();
    I want to calculate and save the result in cal based on the users selection. I want to save the result in cal and display it to the user and also use it in later calculations, how can I do that?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @fitnesspreponline,

    Javascript is a case sensitive language, please, do not confuse the conditional statement “if”, with the “IF” operation implemented in the plugin. Furthermore, why you are assigning a value the “cal” variable in the “return” statement?. The correct code would be:

    (function () {
    	if (fieldname5 == 1)
    		return 10*fieldname8*0.454+ 6.25*(fieldname6*12+fieldname7)*2.54-5*fieldname2+5;
    	if (fieldname5 == 2)
    		return 10*fieldname8*0.454+6.25*(fieldname6*12+fieldname7) * 2.54-5*fieldname2-161;
    })();
    

    If you need additional help implementing your formulas, I can offer you a custom coding service through my private website:

    http://cff.dwbooster.com/customization

    Best regards.

    Thread Starter fitnesspreponline

    (@fitnesspreponline)

    @codepeople what if I want to save the result of the calculation in cal and then display it to the user?
    EDIT: Nevermind, I figured it out. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to code if else in a function’ is closed to new replies.