• Resolved luisef

    (@luisef)


    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 to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @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

    (@luisef)

    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.