• Resolved Simba

    (@simbalion)


    Hi, I want to do something like this:
    (function){
    if(fieldname1=true) return (fieldname2+fieldname3);
    if(fieldname1=false) return (fieldname3-fieldname2);
    }

    Is it possible to create a conditional statement based on the status of a checkbox, and if so what is the correct syntax? I couldn’t find anything about this in the documentation on the website.. 🙂

    https://wordpress.org/plugins/calculated-fields-form/

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

    (@codepeople)

    Hi,

    Yes, that’s possible, and it is very simple, if the checkboxes are not ticked, its value is 0, so, you can use any of following equations:

    First option:

    (function(){
    if(fieldname1) return fieldname2+fieldname3;
    return fieldname3-fieldname2;
    })()

    Second option:

    IF(fieldname1, fieldname2+fieldname3, fieldname3-fieldname2)

    Third option:

    (fieldname1)?fieldname2+fieldname3:fieldname3-fieldname2

    All previous options are a valid solution to your equation.

    Best regards.

    Thread Starter Simba

    (@simbalion)

    Thanks!

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

The topic ‘Using if() with checkboxes’ is closed to new replies.