• Resolved sashiro77

    (@sashiro77)


    Hi.

    I’m trying to calculate a field based on value from one numeric field and one checkbox value.

    I can’t get it to work as my function in the calculated field doesn’t show anything. Don’t know why.

    Fieldname8 is my checkbox where I have assigned value 1,2,3,4 and checked “Value to submit->Choice value”.

    Can you help?

    (function(){
    
         if(fieldname8 = 1) return fieldname1*0.040705;
    
         if(fieldname8 = 2) return fieldname1*0.04652;
            
         if(fieldname8 = 3) return fieldname1*0.052335;
            
         if(fieldname8 = 4) return fieldname1*0.05815;
    
    })();
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @sashiro77

    In javascript the operator for equality is double symbol: “==” because the symbol: “=” is used for assignment.

    By the way, if the fieldname8 is a checkbox field the field’s value would be sum of ticked choices. So, in this case, I recommend you to use the a radio buttons field.

    And the equation would be similar to:

    
    (function(){
         if(fieldname8 == 1) return fieldname1*0.040705;
         if(fieldname8 == 2) return fieldname1*0.04652;   
         if(fieldname8 == 3) return fieldname1*0.052335;   
         if(fieldname8 == 4) return fieldname1*0.05815;
    })();
    

    or

    
    fieldnam1*(function(){
        switch(fieldname8){
            case 1: return 0.040705;
            case 2: return 0.04652;   
            case 3: return 0.052335;   
            case 4: return 0.05815;
        }
    })()
    

    Best regards.

    Thread Starter sashiro77

    (@sashiro77)

    Thank you very much

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can’t get complex function to work’ is closed to new replies.