How to Count Checked Boxes in PDF Forms Using Acrobat JavaScript
Question details
The user needs a method to dynamically count the total number of selected checkboxes in a PDF form containing hundreds of checkboxes and display the exact numeric result.

- Product
- Adobe Acrobat / PDF Forms
- Device & OS
- not provided
- Scenario
- Managing a large PDF form with numerous checkboxes and needing an automated way to tally the selections.
- Observed behavior
- A counter field is required to accurately display the number of selected boxes, including showing zero when no boxes are checked.
Ensure that you have access to a PDF editor that supports JavaScript calculations, such as Adobe Acrobat Pro, and that your form's checkboxes are correctly configured and named.
Use a Document-Level Custom Calculation Script
Add a JavaScript loop to a designated text field to automatically calculate and display the total number of checked boxes across the entire form.
This method uses a JavaScript loop to iterate through every field in the PDF document. If the field is a checkbox and its value is not "Off" (indicating it has been checked), the counter increases. The final count is then displayed in your designated calculation field.
Open your PDF form in your advanced PDF editor (like Adobe Acrobat Pro) and navigate to the Form Editing or Prepare Form mode.
Create a new Text Field where you want the total count to appear on your document. Give it a recognizable name, such as "TotalCount".
Right-click the newly created Text Field, select "Properties", and navigate to the "Calculate" tab.
Select "Custom calculation script" and click the "Edit" button. Paste the following script into the JavaScript editor: var total = 0; for (var i = 0; i < this.numFields; i++) { var name = this.getNthFieldName(i); var field = this.getField(name); if (field.type == "checkbox" && field.value != "Off") total++; } event.value = total;
Click "OK" to save the script and close the properties window. Exit the form editing mode and test the form by checking a few boxes to ensure the total updates accurately.

Log Checked Boxes to the JavaScript Console
Use a script to simply count and print the total number of checked boxes in the JavaScript console for debugging or administrative review.
Manage and Fill PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to effortlessly view, fill, and manage interactive PDF forms, ensuring compatibility and ease of use.
- 1. Download WPS Office: Download and install the free WPS Office suite from the official website.
- 2. Open Your PDF Form: Launch WPS PDF and open your interactive PDF document containing the checkboxes.
- 3. Fill Out the Form: Easily click on checkboxes and text fields to fill out your document with a smooth interface.
- 4. Save or Share: Save your completed form or export it securely to share with others.

Frequently Asked Questions
Why is my PDF JavaScript counter not updating instantly?
By default, calculation scripts run when a field value changes or the form is recalculated. Ensure your checkboxes have the 'Commit selected value immediately' option checked in their individual properties so the total updates as soon as a box is clicked.
Can I count only specific checkboxes instead of all of them?
Yes. You can modify the JavaScript to only count checkboxes with a specific prefix in their field name. For example, use a naming convention like 'chk_item1' and 'chk_item2', and then add a condition in your loop to check if the field name starts with 'chk_' before counting it.
What does 'field.value != "Off"' mean in the Acrobat JavaScript?
In standard PDF forms, a checkbox's default unselected export value is designated as 'Off'. When checked, it takes on its defined export value (usually 'Yes' or 'On'). Checking that the value is not 'Off' is the most reliable way to identify that the box has been selected.




