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

sum to trigger a check box

New Here ,
Jan 10, 2025 Jan 10, 2025

Copy link to clipboard

Copied

Hi! 

I'm trying to have a sum range trigger the showing of a check mark on a field. 

 

For example if sum total is 19 a check mark will show up in box 1 because it is below 20.

If sum total is 28 a check mark will show up in box 3 becasue it is between 25-30.

I'm a novice at Adobe and your help is greatly appreciated! 

 

ElenaBRavenhill_1-1736524159492.png

 

 

 

 

TOPICS
How to , JavaScript , Modern Acrobat , PDF , PDF forms

Views

283

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
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Jan 10, 2025 Jan 10, 2025

Copy link to clipboard

Copied

Enter the following custom calculation script in the Sum field and change the field names to match your check boxes:

event.value<20?this.getField("Check Box1").checkThisBox(0,true):this.getField("Check Box1").checkThisBox(0,false);
(event.value>19 && event.value<25)?this.getField("Check Box2").checkThisBox(0,true):this.getField("Check Box2").checkThisBox(0,false);
(event.value>24 && event.value<31)?this.getField("Check Box3").checkThisBox(0,true):this.getField("Check Box3").checkThisBox(0,false);
(event.value>40 && event.value<46)?this.getField("Check Box4").checkThisBox(0,true):this.getField("Check Box4").checkThisBox(0,false);
event.value>45?this.getField("Check Box5").checkThisBox(0,true):this.getField("Check Box5").checkThisBox(0,false);

View solution in original post

Votes

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
community guidelines
Community Expert ,
Jan 10, 2025 Jan 10, 2025

Copy link to clipboard

Copied

Enter the following custom calculation script in the Sum field and change the field names to match your check boxes:

event.value<20?this.getField("Check Box1").checkThisBox(0,true):this.getField("Check Box1").checkThisBox(0,false);
(event.value>19 && event.value<25)?this.getField("Check Box2").checkThisBox(0,true):this.getField("Check Box2").checkThisBox(0,false);
(event.value>24 && event.value<31)?this.getField("Check Box3").checkThisBox(0,true):this.getField("Check Box3").checkThisBox(0,false);
(event.value>40 && event.value<46)?this.getField("Check Box4").checkThisBox(0,true):this.getField("Check Box4").checkThisBox(0,false);
event.value>45?this.getField("Check Box5").checkThisBox(0,true):this.getField("Check Box5").checkThisBox(0,false);

Votes

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
community guidelines
New Here ,
Jan 10, 2025 Jan 10, 2025

Copy link to clipboard

Copied

Oh Whoa! Thank you!

When I run the above provided formula, it now removes the sum value (first option provided by the system) that was selected. 

Is there a way to have both options? Sum and Custom?

ElenaBRavenhill_0-1736537063345.png

 

Votes

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
community guidelines
Community Expert ,
Jan 10, 2025 Jan 10, 2025

Copy link to clipboard

Copied

No, you can't have both options, but you can add the calculation to your current script, add this to custom calculation script (above your script):

var total = 0;
for(var i=10; i<=15; i++){
 var f = this.getField(""+i).valueAsString;
 if (f !== "" && !isNaN(Number(f)))
  total+=Number(f);}
event.value = total;

Votes

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
community guidelines
New Here ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

Thank you!

I added the calculation above the script, which works, but now the check boxes don't work. 
Is there something I'm missing?

 

ElenaBRavenhill_0-1736777303851.pngElenaBRavenhill_1-1736777360450.png

 

Votes

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
community guidelines
New Here ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

does adding symbols in the field name mess with the formulation? Should I re-name (image below) the field names?

These are the names of the 5 check boxes

ElenaBRavenhill_0-1736778654114.png

 

Votes

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
community guidelines
New Here ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

I'm trying to have the "calculation order" be:

1. The total answers 10 - 15

2. check box appears in the corresponding area range.

For example:

Total is calculated to be 23 then it should trigger a check mark to appear in the area 20-24. 

 

Votes

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
community guidelines
Community Expert ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

Can you upload the form?

Votes

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
community guidelines
New Here ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

Yeah! 🙂

Votes

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
community guidelines
Community Expert ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

There's an error in this line of my script:

event.value>40 && event.value<46

The 40 should be 30.  Also, your checkboxes are hidden so you won't see the results unless you unhide them.

Votes

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
community guidelines
New Here ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

That correction worked! YIPPIE!

Is there a way to have all the boxes hidden except for the one corresponding to the total?

Votes

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
community guidelines
Community Expert ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

LATEST

Yes, but it you don't want users to be able to interact with the check boxes, but still see the results, I would suggest setting the readonly property to true by selecting the Read Only boxes in the General tab of the check box properties.

Votes

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
community guidelines
Community Expert ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

Calculations run every time a field value changes, so this calculation will run every time you check one of the boxes.  When the calculation runs, it will check and uncheck boxes according to the calculation. If you want the check boxes to override the calculation you will have to move the script I provided to another calculation field and put some conditions on the calculation (thanks to @Nesa Nurani for this):

https://pdfautomationstation.substack.com/p/another-method-for-calculation-vs

 

Votes

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
community guidelines
Community Expert ,
Jan 10, 2025 Jan 10, 2025

Copy link to clipboard

Copied

I didn't know it already had a calculation.  You can leave your calculation and move my script above to the custom calculation for another field, but change all of the event words to this.getField("Sum") [or whatever the name of your Sum field is].  Make sure this field calculates after the Sum field in the calculation order.

Votes

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
community guidelines
New Here ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

insightful read on the calculation order! Thank you for sharing!

I tried to subscribe to the newsletter (admin@ridgewealth.com), however the page gives a error code. 

 

Votes

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
community guidelines
Community Expert ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

Thank you.  What is the error code?

Votes

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
community guidelines
New Here ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

something went wrong. 

ElenaBRavenhill_0-1736778999827.png

 

Votes

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
community guidelines
Community Expert ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

I'll subscribe you.

Votes

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
community guidelines
New Here ,
Jan 13, 2025 Jan 13, 2025

Copy link to clipboard

Copied

Thank you! 😄 

Votes

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
community guidelines