• Resolved loikjun1988

    (@loikjun1988)


    Hi, I want to create a calculation based on the dropdown selected.

    I have a dropdown (fieldname7) with 2 options A and B. For A I set the Value as 1, for B I set the value as 2.

    The formula I created for my grand total field6 is:

    (function(){

    If(fieldname7==1) return fieldname1*15;

    If(fieldname7==2) return fieldname1*20;

    })();

    Any idea why it wont work?

    Every help is much appreciated!

    • This topic was modified 5 years, 2 months ago by loikjun1988.

    The page I need help with: [log in to see the link]

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

    (@codepeople)

    Hello @loikjun1988

    Javascript is a case-sensitive language. The correct code would be:

    
    (function(){
    
    if(fieldname7==1) return fieldname1*15;
    
    if(fieldname7==2) return fieldname1*20;
    
    })();
    

    The previous equation can be simplified as follows:

    
    (function(){
    if(fieldname7==1) return fieldname1*15;
    return fieldname1*20;
    })();
    

    Even more using the “IF” operation distributed with the plugin (please, do not confuse it with the “if” conditional statement of javascript)

    
    fieldname1*IF(fieldname7==1, 15, 20)
    

    Best regards.

    Thread Starter loikjun1988

    (@loikjun1988)

    Lovely, thank you!!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Dropdown as value’ is closed to new replies.