• Resolved zduni

    (@zduni)


    How can I count selected fields (not value) to show another Calculated Field.
    Example:
    IF minimum 5 selected fields -> than show Calculated Field (discount 10%)

    THX
    Lukas

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

    (@codepeople)

    Hello @zduni,

    If you are talking about the choices into a checkboxes field, for example the fielname1, the piece of code to use in the equation would be:

    (function(){
    var total = fieldname1, count = jQuery('[id="fieldname'+'1_"]:checked');
    if(5<=count) return total*0.9;
    return total;
    })()

    and that’s all.

    Best regards.

    Thread Starter zduni

    (@zduni)

    what about all fields in the form not only “fieldname1”?

    Plugin Author codepeople

    (@codepeople)

    Hello,

    Assuming that the list of fields is fieldname1, fieldname2, fieldname3, fieldname4, fieldname5, fieldname6, fieldname7, fieldname8, fieldname9, and fieldname10, and that current equation is the sum of all of them:

    fieldname1+fieldname2+fieldname3+fieldname4+fieldname5+fieldname6+fieldname7+fieldname8+fieldname9+fieldname10

    In this case the equation can be edited as follows:

    (function(){
    var total = fieldname1+fieldname2+fieldname3+fieldname4+fieldname5+fieldname6+fieldname7+fieldname8+fieldname9+fieldname10, count=0;
    if(fieldname1) count++;
    if(fieldname2) count++;
    if(fieldname3) count++;
    if(fieldname4) count++;
    if(fieldname5) count++;
    if(fieldname6) count++;
    if(fieldname7) count++;
    if(fieldname8) count++;
    if(fieldname9) count++;
    if(fieldname10) count++;
    
    if(5<=count) return total*0.9;
    return total;
    })()

    and that’s all.

    If you need additional help implementing your project, I can offer you a custom coding service through my personal website:

    https://cff.dwbooster.com/customization

    Best regards.

    Thread Starter zduni

    (@zduni)

    the if(5<=count) seems not to working, give me everytime 100% not 90%. If I for the test write only if(count) than the summe is ok 90%.

    Plugin Author codepeople

    (@codepeople)

    Hello,

    Please, send me the link to the webpage where the form is inserted, and indicate the name of the calculated field.

    Best regards.

    Thread Starter zduni

    (@zduni)

    Hi, please give me your email.

    Plugin Author codepeople

    (@codepeople)

    Hello,

    If you prefer, you can create a ticket in my personal website:

    https://cff.dwbooster.com/contact-us

    Best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Count selected fields’ is closed to new replies.