Title: If function
Last modified: June 15, 2020

---

# If function

 *  Resolved [luisef](https://wordpress.org/support/users/luisef/)
 * (@luisef)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/if-function-3/)
 * Hi, I’m starting using Calculated Fields Form and I’m VERY VERY newbie on this
   matter.
    I’ve tried creating a conditional IF formula using the Calculated Field.
   The purpose is simple if fieldname5 (also a calculated field) as result 1 then
   it should appear “number one”, if 2 “number two” if 3 “number three”. I’ve tried
   IF(fieldname5=1,“number one”, ) IF(fieldname5=2,“number two”, ) IF(fieldname5
   =3,“number three”, ) but nothing shows on this field as result. Can anyone please
   give me some help?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fif-function-3%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/if-function-3/#post-12989084)
 * Hello [@luisef](https://wordpress.org/support/users/luisef/)
 * There are some issues in your equation. First, in javascript the operator for
   equality is the double symbol: “==” because the symbol “=” is used for assignment.
 * Second, the structure of the “IF” operation is: `IF(condition, result if true,
   result if false)`
 * Furthermore, the IF operations can be nested.
 * So, your equation can be implemented as follows:”
 *     ```
       IF(fieldname5==1, "number one", IF(fieldname5==2,"number two", "number three"))
       ```
   
 * Using the third party operator of javascript:
 *     ```
       (fieldname5==1) ?  "number one" : ((fieldname5==2) ? "number two" : "number three")
       ```
   
 * Using the function structure, and the “if” conditional statement (please, do 
   not confuse it with the “IF” operation in the plugin):
 *     ```
       (function(){
           if(fieldname5==1) return "number one";
           else if(fieldname5==2) return "number two";
           return "number three";
       })()
       ```
   
 * Using the switch conditional statement of javascript:
 *     ```
       (function(){
           switch(fieldname5){
               case 1: return "number one";
               case 2: return "number two";
               default: return "number three";
           }
       })()
       ```
   
 * All previous equation are equivalent.
 * Best regards.
 *  Thread Starter [luisef](https://wordpress.org/support/users/luisef/)
 * (@luisef)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/if-function-3/#post-12989367)
 * Grate!
    Thank you very much for your attention and rapid response. Simply amazing!
   I’ve understood the reasoning and changed it by default to “” instead of “number
   three”. That solves totally my problem. Best regards.

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

The topic ‘If function’ 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: [luisef](https://wordpress.org/support/users/luisef/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/if-function-3/#post-12989367)
 * Status: resolved