Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Checkbox Script Help Needed

Community Beginner ,
May 15, 2019 May 15, 2019

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!

TOPICS
Acrobat SDK and JavaScript , Windows
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , 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);

Translate
LEGEND ,
May 15, 2019 May 15, 2019

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

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

Currently

Checkbox-AL
Checkbox-MS
Checkbox-LA

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 15, 2019 May 15, 2019
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! 

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