How to Sum Checkbox Export Values with Acrobat JavaScript
Question details
The user needs to sum the export values of multiple selected checkboxes in an Acrobat PDF form using JavaScript, but the current script replaces the total on each loop instead of adding to it.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating or troubleshooting an interactive PDF form that calculates a total score or price based on user-selected checkboxes.
- Observed behavior
- The calculation script overwrites the total value on each loop iteration instead of accumulating the sum of all checked boxes.
Ensure that all your checkboxes have specific numeric export values assigned in their properties, and note down their exact field names for the script.
Correct the JavaScript Loop to Accumulate Values
Modify the custom calculation script to initialize a total variable and use the '+=' operator to add each checkbox's export value, preventing the total from being overwritten.
When calculating sums using a JavaScript loop, assigning a value directly to the total variable (e.g., total = value) will overwrite previous iterations. You must use the addition assignment operator (+=) to maintain a running total.
Open your PDF form in 'Prepare Form' mode. Right-click the target calculation text field, select 'Properties', and navigate to the 'Calculate' tab.
Select 'Custom calculation script' and click the 'Edit' button to open the JavaScript editor.
At the very top of your script, initialize the total as a number by typing: var total = 0;
Modify your loop to accumulate the values. Change your existing assignment to: total += Number(this.getField('C' + i).valueAsString);
At the end of the script outside the loop, assign the accumulated sum to the field value by adding: event.value = total; Click 'OK' to save.

Use Acrobat's Built-in Sum Calculation
Avoid JavaScript entirely by using the native calculation properties to sum the selected fields automatically.
Easily Manage PDF Forms with WPS Office
WPS Office offers a comprehensive PDF editor that allows you to effortlessly fill out interactive forms, add annotations, and manage your documents without complex programming.
- 1. Open your PDF: Launch WPS Office and open your interactive PDF form using the WPS PDF tool.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view available form fields and interactive elements.
- 3. Fill or Edit Fields: Click on the checkboxes or text fields to enter your data or modify the form inputs.
- 4. Save and Export: Once your form is filled and calculations are verified, click 'Save' or export the document to share it securely.

Frequently Asked Questions
Why is my Acrobat JavaScript calculation only returning the value of the last checkbox?
This happens if you use the standard assignment operator (=) instead of the addition assignment operator (+=) in your script loop. The script overwrites the total on each iteration instead of adding the current value to the running total.
Do I absolutely need JavaScript to sum checkbox values in a PDF form?
No, you do not need JavaScript if you only want a simple sum. You can use Acrobat's built-in calculation properties. Under the field's 'Calculate' tab, simply select 'Value is the sum (+) of the following fields' and pick your checkboxes.
What does 'valueAsString !== "Off"' mean in Acrobat JavaScript?
In Acrobat PDF forms, unchecked checkboxes typically return the default export value of "Off". Checking this condition ensures the script only processes and converts checkboxes that have been actively selected by the user.
How do I set the correct export value of a checkbox in Acrobat?
Right-click the checkbox, select 'Properties', and go to the 'Options' tab. In the 'Export Value' text box, enter the specific numeric value you want the checkbox to represent when a user selects it.




