Skip to main content
Participant
May 15, 2019
Answered

Checkbox Script Help Needed

  • May 15, 2019
  • 1 reply
  • 1083 views

Ok so the problem I'm having building a PDF where I have to use checked checkboxes to determine a specific total amount that is entered into a different field. The issue is that there's no way to calculate the amounts with the checkbox value alone because the math doesn't split evenly. The price is based on a step up of $50 for each additional box that's checked. Is there a way to show a specific total/text based on how many of the checkboxes is checked? Or is there an efficient way to give the 1st checked box and value and then add the additional $50 for each additional box checked?

I need a script that shows a total based on three different scenarios:

any 1 of 3 boxes checked = $375
any 2 of 3 boxes checked = $425
any 3 of 3 boxes checked = $475

Normally I can tailor scripts to suit my needs, but this one has me stumped because I'm not even sure how to phrase my search.
Please help!

This topic has been closed for replies.
Correct answer try67

You can use this code as the custom calculation script of your field:

var fields = ["Checkbox-AL", "Checkbox-MS", "Checkbox-LA"];

var total = 0;

for (var i in fields) {

    var f = this.getField(fields);

    if (f.valueAsString!="Off") total++;

}

if (total==0) event.value = 0;

else event.value = 325 + (50 * total);

1 reply

Inspiring
May 15, 2019

Yes, that's possible. What are the field names of the three check boxes?

Rocky7Author
Participant
May 15, 2019

Currently

Checkbox-AL
Checkbox-MS
Checkbox-LA

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 15, 2019

You can use this code as the custom calculation script of your field:

var fields = ["Checkbox-AL", "Checkbox-MS", "Checkbox-LA"];

var total = 0;

for (var i in fields) {

    var f = this.getField(fields);

    if (f.valueAsString!="Off") total++;

}

if (total==0) event.value = 0;

else event.value = 325 + (50 * total);