• Resolved xsajdq

    (@xsajdq)


    I have probably simple problem, but I was trying to solve it for so long that Im geting realy angry.
    So…
    I have fieldname1 which is the result of equation.
    I have checkbox that is fieldname2. Values in checkbox are:
    Mark = Value1
    Adam = Value2
    Victor = Value3

    I want to change fieldname1 depending on which checkbox is checked.

    In fieldname1 I was trying to do:

    if (fieldname2,1 == true){ }
    if (fieldname2,1,2){ }

    Nothing of that is working

    • This topic was modified 4 years, 1 month ago by xsajdq.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @xsajdq

    Your code contains multiple parser errors. I’ll try to describe the process with a hypothetical example:

    First, you are using a checkbox field, which means that multiple choices can be ticked at once. If you want to check only one choice at once, you should use a Radio Buttons field.

    Assuming the choices’ values are 1, 2, and 3, respectively. If you want to check the choices ticked by separate you must untick the “Merge ticked up options (sum or concatenation) or their values are returned as an array.” attribute in the settings of the checkbox field. Now, its value would be an array with the values of ticked choices, and you can use the “IN” operation in the equation.

    For example:

    
    (function(){
    var result = [];
    if(IN(1, fieldname1)) result.push('Mark is ticked');
    if(IN(2, fieldname1)) result.push('Adam is ticked');
    if(IN(3, fieldname1)) result.push('Victor is ticked');
    return result.join(' and ');
    })()
    

    Best regards.

    Thread Starter xsajdq

    (@xsajdq)

    Thanks for help, but I wanted something different ??

    I changed code that you written a little bit and it worked as I wanted.

    Thanks a lot!

    • This reply was modified 4 years, 1 month ago by xsajdq.
    Plugin Author codepeople

    (@codepeople)

    Hello @xsajdq

    You described the problem for the cases where only one choice is ticked. As I said previously, in the checkbox fields, the users can tick multiple choices at once.

    For example, what should be the result if the user ticks choice one and choice two at once?

    Best regards.

    Thread Starter xsajdq

    (@xsajdq)

    I’ve edited my lst answer. Ffter trying some other way that you showed all is working as I wanted.
    I added to my fieldname1 code

    if(IN(1, fieldname2))
    {
    prec(fieldname1*0.8,0)
    }
    if(IN(2, fieldname2))
    {
    prec(fieldname1*0.6,0)
    }
    

    and everything is working as I wanted

    • This reply was modified 4 years, 1 month ago by xsajdq.
    Plugin Author codepeople

    (@codepeople)

    Hello @xsajdq

    If you want to round the result to an integer, it is preferred the use of the ROUND operation:

    
    (function(){
    if(IN(1, fieldname2)) return ROUND(fieldname1*0.8);
    if(IN(2, fieldname2)) return ROUND(fieldname1*0.6);
    })()
    

    More information about the rounding operations by reading the following post in the plugin’s blog:

    https://cff.dwbooster.com/blog/2020/09/20/rounding-numbers/

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to change final value using checkboxes’ is closed to new replies.