PDF Editing Issues

How to Sum Checkbox Export Values with Acrobat JavaScript

John WilsonJohn Wilson Nov 5, 2026 870 views

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.

How to Sum Checkbox Export Values in Acrobat PDF Forms
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.
Before you start

Ensure that all your checkboxes have specific numeric export values assigned in their properties, and note down their exact field names for the script.

Solution 1Recommended

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.

1
Open Calculation Properties

Open your PDF form in 'Prepare Form' mode. Right-click the target calculation text field, select 'Properties', and navigate to the 'Calculate' tab.

2
Edit the Custom Script

Select 'Custom calculation script' and click the 'Edit' button to open the JavaScript editor.

3
Initialize the Total Variable

At the very top of your script, initialize the total as a number by typing: var total = 0;

4
Update the Loop Operator

Modify your loop to accumulate the values. Change your existing assignment to: total += Number(this.getField('C' + i).valueAsString);

5
Assign the Final Value

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.

Correct the JavaScript Loop to Accumulate Values
Check Off Values: Make sure your script includes an 'if' statement to ignore unchecked boxes, such as: if (this.getField('C' + i).valueAsString !== 'Off').
WPS PDF Form Editor

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. 1. Open your PDF: Launch WPS Office and open your interactive PDF form using the WPS PDF tool.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view available form fields and interactive elements.
  3. 3. Fill or Edit Fields: Click on the checkboxes or text fields to enter your data or modify the form inputs.
  4. 4. Save and Export: Once your form is filled and calculations are verified, click 'Save' or export the document to share it securely.
Create, read, and fill interactive PDF forms seamlessly.Fully compatible with standard Adobe PDF and Microsoft Office formats.Lightweight software that ensures smooth performance.Rich annotation, conversion, and signature tools included.
microsoft office alternative - wps office

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.