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

    (@codepeople)

    Hi,

    I’ll try to explain the process with an example:

    Assuming your current equation is: fieldname1*fieldname2, and you want insert in the form a checkbox field (I’ll call it fieldname3), and if the checkboxes are ticked, the equation should be: fieldname4*100

    In this case the equation associated to the calculated field should be modified as follows:

    IF( fieldname3, fieldname4*100, fieldename1*fieldname2)

    other possible equations are:

    (fieldname3) ? fieldname4*100 : fieldename1*fieldname2)

    and

    (function(){
    if( fieldname3 ) return fieldname4*100;
    return fieldename1*fieldname2;
    })()

    Pay attention to the previous variants of the equation, in each of them I’ve used a different way to express a conditional statement, the first one uses the operation: “IF(condition, if true, if false)” included by the plugin, the second one used the ternary operator of javascript: “(condition) ? if true : if false”, and the last one uses the conditional statement of javascript.

    If you need additional help, I can offer you a custom coding service:

    http://cff.dwbooster.com/customizatio

    Best regards.

    Thread Starter 1147249

    (@notdgs)

    Thank you for the prompt response.

    Yes, I got this far. But my problem is that the original equation is more complex. There are three if statements there. And I’m not sure whether it is possible to use some kind of nesting in your plugin.

    The orig equation for fieldname2 goes like this:

    (function(){
    IF ((fieldname1>0) and (fieldname1<=10)) return fieldname1*200;
    IF ((fieldname1>10) and (fieldname1<=50)) return fieldname1*150;
    IF ((fieldname1>50) and (fieldname1<=100)) return fieldname1*100;
    })();

    The actual calculation is more complex, but you get the idea.

    So how do I put this code together with your

    (function(){
    IF(fieldname3) return fieldname1*100;
    return ***HOW DO I PUT ALL OF THE ABOVE HERE?***;
    })()

    I was able to solve this by creating two price totals and hiding one or the other. But for that I used a drop down field, not two check boxes.

    Plugin Author codepeople

    (@codepeople)

    Hi,

    First, javascript is a case sensitive language, if you use the “IF” operation included with the plugin, you should use the correct format for this operation, the same occurs if you want to use the “if” conditional statement of javascript, they are different.

    Second, the “and” operator in javascript is the symbol “&&”

    Third, the texts should be closed between single or double quotes.

    So, the previous equations should be corrected as follows:

    (function(){
    if( fieldname1>0 && fieldname1<=10 ) return fieldname1*200;
    if( fieldname1>10 && fieldname1<=50 ) return fieldname1*150;
    if( fieldname1>50 && fieldname1<=100 ) return fieldname1*100;
    })()

    and

    (function(){
    if(fieldname3) return fieldname1*100;
    return '***HOW DO I PUT ALL OF THE ABOVE HERE?***';
    })()

    Best regards.

    Thread Starter 1147249

    (@notdgs)

    Thanks for the clarification. In the equation I actually used the correct syntax, just as you described it.

    The problem remains, though… 🙂

    What I don’t know is how to put the first function / calculation inside the second function, instead of the placeholder text ***HOW DO I PUT ALL OF THE ABOVE HERE?***

    I’m not sure that I’m making this clear enough. I want to override the original calculation if one of two check boxes is checked.

    I haven’t found a way to do that.

    Plugin Author codepeople

    (@codepeople)

    Hi,

    Could you send me the link to your webpage to check the form in action, please?

    Best regards.

    Thread Starter 1147249

    (@notdgs)

    Hi, I sent you the link via your web form a moment ago.

    Plugin Author codepeople

    (@codepeople)

    Hi,

    I’m sorry, but none of the equations or fields, in the form you sent me through my support system, are related with the questions in this support thread.

    Best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘use checkboxes to override calculation’ is closed to new replies.