Title: Conditional radio values
Last modified: March 11, 2021

---

# Conditional radio values

 *  Resolved [spacebom](https://wordpress.org/support/users/spacebom/)
 * (@spacebom)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/conditional-radio-values/)
 * I want to set different radio values depending the value of another field.
 * For example, I have the field “size” (1-100), and the radio field “color” with
   two options: “red” and “blue” with default values 15 for “red”, and 30 for “blue”.
 * If you select size>50 and option “red” the default value is correct, but if you
   select size>50 i want to set the value for the option “red” to 18, instead of
   15. And if you select “blue”, set value to 34.
 * I tried with this formula but does not working:
 *     ```
       IF size>50 {
        IF color=='red' {
         color=18
        } 
        IF color=='blue' {
         color=34
        } 
       }
       ```
   
 * The complete formula I am trying to calculate is:
 * `(fieldname18*(fieldname16+(IF fieldname18>=180 {IF fieldname17=='blue' {fieldname17
   =1300} IF fieldname17=='red' {fieldname17=1450} ELSE { IF fieldname17=='blue'{
   fieldname17=1250} IF fieldname17=='red' {fieldname17=1400})))+(fieldname19*900)
   +(fieldname20*750)+(fieldname21*750)`
 * I think i am doing it wrong so I appreciate if you could help me.
 * Thank you very much.
    -  This topic was modified 5 years, 2 months ago by [spacebom](https://wordpress.org/support/users/spacebom/).

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

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/conditional-radio-values/#post-14166059)
 * Hello [@spacebom](https://wordpress.org/support/users/spacebom/)
 * There are some errors in your equation:
 * First, javascript is a case-sensitive language, and the structure of the “if”
   conditional statement in your equation is incorrect.
 * Second, you cannot use the fields’ names as variables that receive values because
   the plugin replaces them in the equations by their corresponding values.
 * I guess you are interpreting the problem in the wrong way. The values of the 
   radio buttons are always the same: blue and red. You interpret them as you want
   as part of the equations.
 * I cannot give you a fixed structure of your equation because I don’t understand
   it. However, I’ll try to describe the process with a hypothetical example:
 * Assuming the size field is the fieldname1 and the radio buttons for colors the
   fieldname2. Furthermore, you have another two fields for width and height: fieldname3
   and fieldname4, respectively.
 * And you want to evaluate the equation: size*color*width*height
    But the numeric
   number of color depends on size and color:
 * If 50<size and the color selected is red, then the value would be 18, and if 
   the color selected is blue, the value would be 34. However, if size<=50, the 
   corresponding values for colors would be 15 and 30.
 * A possible equation corresponding to this hypothetical example would be:
 *     ```
       (function(){
           var color_value;
   
           if(fieldname1<=50)
           {
               if(fieldname2 == 'red') color_value = 15;
               else color_value = 30;
           }
           else
           {
               if(fieldname2 == 'red') color_value = 18;
               else color_value = 34;
           }
   
           return fieldname1*color_value*fieldname3*fieldname4;
       })()
       ```
   
 * Best regards.
 *  Thread Starter [spacebom](https://wordpress.org/support/users/spacebom/)
 * (@spacebom)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/conditional-radio-values/#post-14166480)
 * Thank you very much, you are amazing.
 * I think I am very near to solve the problem. Your function works fine, except
   I think it don’t match the second “if”, because it always return “30” and “34”
   values no matter what colour (fieldname2) you select.
 * I am using you function:
 *     ```
       (function(){
           var color_value;
   
           if(fieldname18<=180)
           {
               if(fieldname17 == 'red') color_value = 15;
               else color_value = 30;
           }
           else
           {
               if(fieldname17 == 'red') color_value = 18;
               else color_value = 34;
           }
   
           return color_value;
       })()
       ```
   
 * And you can test here: [https://hormitech.es/?cff-form=10](https://hormitech.es/?cff-form=10)
   what I am saying. It always use “red” value, never “catch” the blue value/selection.
 * I am very grateful for your support.
 *  Thread Starter [spacebom](https://wordpress.org/support/users/spacebom/)
 * (@spacebom)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/conditional-radio-values/#post-14166497)
 * And this is my radio field configuration if it helps to add information to explain
   the problem: [https://hormitech.es/wp-content/uploads/2021/03/radio-conf.png](https://hormitech.es/wp-content/uploads/2021/03/radio-conf.png)
 * Thank you again.
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/conditional-radio-values/#post-14166561)
 * Hello [@spacebom](https://wordpress.org/support/users/spacebom/)
 * In the code I sent you previously, the values of radio buttons’ choices must 
   be red and blue and not 800 and 980 (the checkbox ticked in the field’s settings
   affects only the information to submit, but the equations always use the choices’
   values.)
 * If you don’t want to edit the values of the choices, then you must use the correct
   choices’ values in the equation:
 *     ```
       (function(){
           var color_value;
   
           if(fieldname18<=180)
           {
               if(fieldname17 == 800) color_value = 15;
               else color_value = 30;
           }
           else
           {
               if(fieldname17 == 800) color_value = 18;
               else color_value = 34;
           }
   
           return color_value;
       })()
       ```
   
 * Best regards.
 *  Thread Starter [spacebom](https://wordpress.org/support/users/spacebom/)
 * (@spacebom)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/conditional-radio-values/#post-14168751)
 * Oh, you are awesome. Now it is working perfect. Thank you very much for your 
   help.
    Best Regards. David.

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

The topic ‘Conditional radio values’ 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/)

 * 5 replies
 * 2 participants
 * Last reply from: [spacebom](https://wordpress.org/support/users/spacebom/)
 * Last activity: [5 years, 2 months ago](https://wordpress.org/support/topic/conditional-radio-values/#post-14168751)
 * Status: resolved