Title: conditional operations
Last modified: June 3, 2022

---

# conditional operations

 *  Resolved [borgesleti](https://wordpress.org/support/users/borgesleti/)
 * (@borgesleti)
 * [4 years ago](https://wordpress.org/support/topic/conditional-operations/)
 * First of all, I would like to thank you for this great plugin!
 * I’m wondering whether I can make a conditional operation with a predefined end
   value.
    for example: if fieldx>=100 or fieldx <=500, so return fieldx == 20 but
   if fieldx <=500 or fieldx <=1000, so its return fieldx == 50
 * I don’t know how to do this operation or if this is possible.

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

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [4 years ago](https://wordpress.org/support/topic/conditional-operations/#post-15705083)
 * Hello [@borgesleti](https://wordpress.org/support/users/borgesleti/)
 * Thank you very much for using our plugin.
 * I’m sorry, but your conditions don’t have much sense because you are repeating
   the same condition to return different values:
 * fieldx <=500 returns 20
 * fieldx <=500 returns 50
 * So, I will try to describe the process with a hypothetical example.
 * Assuming you have the number field feildname1, and you want to return 20 if the
   fieldname1 is in the range 100<fieldname1 and fieldname2<500, and 50 if fieldname1
   <=100 or 500<=fieldname1.
 * In this hypothetical case, the equation associated with the calculated field 
   could be implemented as follows:
 * Using the function structure and the `if` conditional statement:
 *     ```
       (function(){
       if(100<fieldname1 && fieldname1<500) return 20;
       else return 50;
       })()
       ```
   
 * The same equation by using the `IF` conditional operation (Javascript is a case
   sensitive language, do not confuse the `IF` operation with the `if` conditional
   statement):
 * `IF(100<fieldname1 && fieldname1<500, 20, 50)`
 * Finally, the same equation but this time using the javascript ternary operator:
 * `(100<fieldname1 && fieldname1<500) ? 20 : 50`
 * The three previous equations are equivalent and return the same result.
 * Best regards.
 *  Thread Starter [borgesleti](https://wordpress.org/support/users/borgesleti/)
 * (@borgesleti)
 * [3 years, 12 months ago](https://wordpress.org/support/topic/conditional-operations/#post-15732881)
 * thanks for the support, it worked as explained to me.
    But i have one last question
 * Is it possible to have a conditional that returns a result in Text? For example:
 * If fieldname1>=200 it shows me the text “Positive Result”, Else not it shows 
   me the text “Median Result”
 * But
 * If fieldname1<100 it shows me the text “Negative Result”, Else not it shows me
   the text “Median Result”
 * It’s possible? Or how to do?
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 12 months ago](https://wordpress.org/support/topic/conditional-operations/#post-15734218)
 * Hello [@borgesleti](https://wordpress.org/support/users/borgesleti/)
 * Yes, that’s possible. You can nest `IF` operations as follows:
 * `IF(fieldname1>=200, 'Positive Result', IF(fieldname1<100, 'Negative Result','
   Median Result'))`
 * Best regards.
 *  Thread Starter [borgesleti](https://wordpress.org/support/users/borgesleti/)
 * (@borgesleti)
 * [3 years, 12 months ago](https://wordpress.org/support/topic/conditional-operations/#post-15735942)
 * Thanks for the help, it worked perfectly!!
 *  Thread Starter [borgesleti](https://wordpress.org/support/users/borgesleti/)
 * (@borgesleti)
 * [3 years, 12 months ago](https://wordpress.org/support/topic/conditional-operations/#post-15736506)
 * Could i add this in a function for the text color to change too?
    for example:
 *  if(fieldname1>200) result = ‘Positive Result’; color = ‘Green’;
    if(fieldname1
   >=100) result = ‘Median Result’; color = ‘orange’; if(fieldname1<100) result 
   = ‘Negative Result’; color = ‘red’;
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 12 months ago](https://wordpress.org/support/topic/conditional-operations/#post-15737522)
 * Hello [@borgesleti](https://wordpress.org/support/users/borgesleti/)
 * Yes, that’s possible, but the equation is little more complex. If the calculated
   field is the feildname123, the equation would be:
 *     ```
       (function(){
       var field = getField(123).jQueryRef().find('input'),
       color, result;
       if(fieldname1>200){ result = 'Positive Result'; color = 'Green';}
       else if(fieldname1>=100){ result = 'Median Result'; color = 'orange';}
       else{ result = 'Negative Result'; color = 'red';}
   
       field.css('color', color);
       return result;
       })()
       ```
   
 * The getField operation receives the number component in the field’s name and 
   returns its object representation.
 * Best regards.
 *  Thread Starter [borgesleti](https://wordpress.org/support/users/borgesleti/)
 * (@borgesleti)
 * [3 years, 12 months ago](https://wordpress.org/support/topic/conditional-operations/#post-15737724)
 * Thank you for the help.
    it works perfectly now!!

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

The topic ‘conditional operations’ 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/)

 * 7 replies
 * 2 participants
 * Last reply from: [borgesleti](https://wordpress.org/support/users/borgesleti/)
 * Last activity: [3 years, 12 months ago](https://wordpress.org/support/topic/conditional-operations/#post-15737724)
 * Status: resolved