• Resolved sarahweb

    (@sarahweb)


    Hi

    I ma loving the plugin but I am struggling to get it to work as I need
    fieldname1 = a checkbox yes / no
    fieldname2 – dependancy of the above = number 24, 40, 48, 60 etc
    I would then like
    fieldname3 – to be linked to above if selected YES then 24 display fieldname4 or 0
    fieldname3 – to be linked to above if selected NO then 24 display fieldname5 or 0
    fieldname3 – to be linked to above if selected YES then 48 display fieldname6 or 0

    etc

    So I need a mixture of the IF and AND I think but its not just working out for me

    AND(fieldname2>25,fieldname1=1,fieldname4,0);

    I think I have myself mixed up with IF, AND and Javascript!

    Any help appreciated

    Thanks
    Sarah

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

    (@codepeople)

    Hello Sarah,

    I’m not sure to understand your equation’s description. However, there are some issues in the piece of code you include as reference, in javascript the operator for equality is the double symbol: “==” because the symbol “=” is used for assignment, furthermore in javascript exists the “switch” statement, similar to PHP (you can find it in any javascript tutorial)

    So, coming back to the equation, if the values associated to the choices in the fieldname1 are 0 and 1:

    (function(){
    if(fieldname1 == 1)
    {
      switch(fieldname2)
      {
        case 24: return fieldname4;
        case 48: return fieldname6;
      }
    }
    else
    {
      switch(fieldname2)
      {
        case 24: return fieldname5;
      }
    }
    return 0;
    })()

    of course you should complete the cases.
    Note: I’m not including the statement “break” because each “case” section includes a “return” statement.

    There are other ways to implement the equation, for example, using the “if” statement:

    (function(){
    if(fieldname1 == 1 && fieldname2==24) return fieldname4;
    if(fieldname1 == 1 && fieldname2==48) return fieldname6;
    if(fieldname1 == 0 && fieldname2==24) return fieldname5;
    })()

    Best regards.

    Thread Starter sarahweb

    (@sarahweb)

    Thank you so very much – it all makes so much more sense when you write it like that!!

    Thread Starter sarahweb

    (@sarahweb)

    and that helped hugely and its all working perfectly – thank you very much this really is exactly what I was looking for!

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

The topic ‘Can you do a PHP style switch function?’ is closed to new replies.