PDF Editing Issues

How to Count Selected PDF Checkboxes by Column with JavaScript

Ayan MasoodAyan Masood Nov 2, 2026 869 views

Question details

The user needs to calculate the total number of checked boxes within a specific column of a PDF form using JavaScript.

How to Count Selected PDF Checkboxes by Column with JavaScript
Product
PDF Forms
Device & OS
not provided
Scenario
Creating an interactive PDF form with multiple rows and columns of checkboxes where a total count per column must be displayed in a calculation field.
Observed behavior
A custom calculation script is required to iterate through the checkboxes in the target column and return the sum of the selected ones to a total field.
Before you start

Ensure your PDF form has clearly named checkbox fields and that you are using a PDF editor that supports JavaScript form calculations and field properties.

Solution 1Recommended

Use a Custom Calculation Script with a Field Array

Create an array of specific checkbox names and loop through them in the total field to tally the selected boxes.

This method involves listing the exact names of the checkboxes in your column. The script checks each field's export value to see if it is selected (i.e., not equal to 'Off') and increments the total count.

1
Open Field Properties

Open your PDF form in Edit mode, right-click the text box designated for the column total, and select 'Properties'.

2
Navigate to the Calculate Tab

In the Properties dialog, click on the 'Calculate' tab to set up the field's calculation parameters.

3
Insert Custom Calculation Script

Select the 'Custom calculation script' option and click 'Edit'. Paste the following JavaScript code: var fields = ["checkbox 1", "checkbox 2"]; var total = 0; for (var i = 0; i < fields.length; i++) { var f = this.getField(fields[i]); if (f && f.value != "Off") total++; } event.value = total;

4
Apply and Test

Click 'OK' to save the script, then close the Properties window. Switch to Preview or Form Fill mode and click the checkboxes to ensure the total updates accurately.

Use a Custom Calculation Script with a Field Array
Export Values: Ensure the unchecked export value is explicitly set to 'Off' in the checkbox properties, as this is the standard default for unselected PDF checkboxes.
Powerful PDF Form Editor

Edit and Calculate PDF Forms Easily with WPS Office

WPS PDF provides robust tools for creating interactive forms, setting up checkboxes, and applying custom calculation scripts seamlessly. Manage your document logic without needing expensive software.

  1. 1. Open PDF in WPS Office: Launch WPS Office, open your PDF document, and navigate to the 'Form' tab on the top ribbon.
  2. 2. Access Interactive Fields: Click on 'Text Field' or 'Check Box' to edit existing form elements or draw new ones on the document.
  3. 3. Configure Properties and Scripts: Double-click the desired total field to open its Properties panel, switch to the 'Calculate' section, and easily input your custom JavaScript code.
Advanced PDF form field editing and creationSeamless support for standard PDF JavaScript calculationsHighly compatible with Adobe Acrobat and Microsoft Edge PDF form standardsIntuitive interface for managing text boxes, checkboxes, and radio buttons
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF checkbox calculation returning 0?

This usually happens if the checkbox export value doesn't match the one specified in your script. Ensure your script checks for the exact export value string (e.g., 'Yes'), or verify it is checking that the value is not equal to 'Off'.

Can I group checkboxes in a row to act like radio buttons?

Yes. You can achieve this by giving all checkboxes in the same row the exact same Name under their General properties, but assigning different Export Values to each under the Options tab. Selecting one will automatically deselect the others.

Where do I input the JavaScript code in a PDF form?

Right-click the target field (such as the text box meant to display the total) and select Properties. Navigate to the Calculate tab, choose the 'Custom calculation script' option, and click the Edit button to paste your code.