# Checkbox Script Help Needed

Community Beginner ,
May 15, 2019 May 15, 2019

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.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

354

Likes

Report

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

Most Valuable Participant , May 15, 2019 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);

Likes

4 Replies 4
May 15, 2019 May 15, 2019

Copied

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

Likes

Report

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

Copied

Currently

Checkbox-AL
Checkbox-MS
Checkbox-LA

Likes

Report

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

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

Report

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

Copied

LATEST

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

Report

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