Count Yes and No Checkbox Values with Acrobat JavaScript
Question details
Count selected Yes and No responses separately in a PDF form using Acrobat JavaScript.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A form contains multiple checkbox fields with export values such as yes and no, and needs to calculate response totals.
- Observed behavior
- The current script counts every checkbox value that is not Off, rather than matching the desired export value.
Open the PDF in Adobe Acrobat and choose Prepare a form. Check the field names and each checkbox's export value under Properties > Options; the script must match their exact spelling and capitalization.
Count checkboxes by their exact export value
Use a custom calculation script to count only the checkboxes whose value matches yes or no.
This example assumes the checkbox fields are named Check Box 1 through Check Box 60 and that the Yes export value is lowercase yes. Adjust the field name pattern and range to match your form.
In Acrobat, select Prepare a form, then double-click the text field where you want to display the Yes total.
In the field properties, open Calculate, select Custom calculation script, and click Edit. Enter: var total = 0; for (var i = 1; i <= 60; i++) { var f = this.getField("Check Box " + i); if (f && f.valueAsString == "yes") total++; } event.value = total;
To count No responses separately, open the No total field's Calculate tab and add the same script, replacing "yes" with the exact No export value, such as "no".
Close the field properties and use Preview in Prepare a form. Select and clear several checkboxes to verify that each total changes as expected.

View and edit PDF documents with WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface for working with PDFs and Office documents. Open existing files to make migration easy. Acrobat-specific JavaScript calculations should still be created and tested in Acrobat.

Frequently Asked Questions
Why does checking for a value other than Off count both Yes and No?
Both yes and no are selected export values, so both differ from Off. Compare the field's valueAsString with the exact value you want to count instead.
Where can I find a checkbox's export value?
In Acrobat, open Prepare a form, double-click the checkbox, and check its export value on the Options tab.
How do I count No responses instead of Yes responses?
In the total field's custom calculation script, replace "yes" with the exact No export value shown in the checkbox properties, such as "no".
What if my checkbox fields have different names?
Change the field name pattern in this.getField("Check Box " + i) to match your form. If the fields are not numbered sequentially, use their actual names instead of relying on the loop's numbering.




