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

Formula for calculating sums with button

New Here ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

I am currently building a scoring chart that can hold a max of 100 people. Each person is then graded on up to 8 criteria fields for a total score. However, when I used the built-in sum formula, it made my form lag and take around 10 seconds to click between boxes. So now I am looking into creating a button that once the form is filled out, the user can click the button to then calculate the sums of the 100 candidates' scores. So first of all, is this possible to create and will it help remove the lag?

 

The list of boxes that need to be added for the first candidate are 11, 21, 31, 41, 51, 61, 71, and 81. Then the second candidate has 12, 22, 32, 42, 52, 62, 72, and 82. This goes on until the 100th candidate who has the boxes 1100, 2100, 3100, 4100, 5100, 6100, 7100, and 8100. Then the boxes for the sums are titled TotalScore1, TotalScore2, up to TotalScore100 respectively.

 

I was able to figure out how to adjust a script to my needs in a previous form, but I don't know how to get started with this one as it is much more advanced. May I please have help with creating a format?

 

Also, for the button, should I choose the "Mouse Up" option?

 

Thank you in advance!

TOPICS
Acrobat SDK and JavaScript

Views

466

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 ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

If you have a lot of calculations, they can be very slow. The reason for this is that every calculation script is called every time any field on the form is changed.  There are lots of ways to make the calculations more efficient and faster. You've already hit on one way, take them all out of the calculation scripts and put them into a button script, so the user has control. 

 

So Yes, you want a MouseUp, "Run a JavaScript" action. But the hard part is writing the script. The easiest thing for you to do is to use a brute force approach. Just write out all the calculations for every field. this is time consuming and error prone (human error), but it's the simplest method. 

 

The general structure will be something like this;

this.getField("TotalScore2").value = this.getField("field1").value + this.getField("field2").value;

 

You can learn more about what you need to do here:

https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

LATEST

If you were using the "Form Field Naming Convention" you would not need JavaScript and just use the calculation functions built into Acrobat Pro.

See this sample PDF:

https://documentcloud.adobe.com/link/track?uri=urn:aaid:scds:US:1c732995-09a8-4dc3-ab3b-661aa1d3f1ab

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