Checkbox Script Help Needed

Community Beginner ,
May 15, 2019

Copy link to clipboard

Copied

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!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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);

TOPICS
Acrobat SDK and JavaScript, Windows

Views

322

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Checkbox Script Help Needed

Community Beginner ,
May 15, 2019

Copy link to clipboard

Copied

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!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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);

TOPICS
Acrobat SDK and JavaScript, Windows

Views

323

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 15, 2019 0
Adobe Community Professional ,
May 15, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 15, 2019 2
Community Beginner ,
May 15, 2019

Copy link to clipboard

Copied

Currently

Checkbox-AL
Checkbox-MS
Checkbox-LA

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 15, 2019 0
Most Valuable Participant ,
May 15, 2019

Copy link to clipboard

Copied

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);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 15, 2019 2
Rocky7 LATEST
Community Beginner ,
May 15, 2019

Copy link to clipboard

Copied

Works like a charm! Thank you very much! try67

Also thank you George_Johnson​! This is the first time we've interacted, but I've read lots of your posts and they've all be super helpful! 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 15, 2019 0