Title: Can&#8217;t get complex function to work
Last modified: November 27, 2020

---

# Can’t get complex function to work

 *  Resolved [sashiro77](https://wordpress.org/support/users/sashiro77/)
 * (@sashiro77)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/cant-get-complex-function-to-work/)
 * 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](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/cant-get-complex-function-to-work/#post-13716303)
 * Hello [@sashiro77](https://wordpress.org/support/users/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](https://wordpress.org/support/users/sashiro77/)
 * (@sashiro77)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/cant-get-complex-function-to-work/#post-13717325)
 * 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.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [sashiro77](https://wordpress.org/support/users/sashiro77/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/cant-get-complex-function-to-work/#post-13717325)
 * Status: resolved