How to Count 'Yes' Answers in Adobe PDF Forms | PDF Form Calculation
Question details
The user needs a calculated field in a PDF form to automatically display the total number of 'Yes' responses from a specific set of Yes/No questions.

- Product
- Adobe Acrobat / PDF Forms
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms, such as surveys, quizzes, or checklists, where tallying specific responses is required.
- Observed behavior
- The total count of 'Yes' responses needs to be automatically calculated and displayed in a designated form field.
Ensure you have access to a PDF editor that supports JavaScript custom calculations, such as Adobe Acrobat Pro, and verify the exact names of your Yes/No form fields before writing the script.
Use a Custom Calculation Script to Count Responses
Apply a short JavaScript code snippet to a text field's calculation properties to automatically tally the 'Yes' answers.
This method uses JavaScript to loop through a sequence of form fields (e.g., Question11 to Question15). It checks each field's value and increments the total count if the value equals 'Yes'.
For this script to work perfectly, your Yes/No fields must have a consistent naming convention, such as a static prefix followed by a sequential number.
Open your PDF form in Adobe Acrobat Pro and select the 'Prepare Form' tool from the right-hand pane.
Right-click the text field where you want the total count to appear (e.g., Section1YesCount) and select 'Properties'.
Go to the 'Calculate' tab, select the 'Custom calculation script' option, and click the 'Edit' button.
Paste the following code into the editor: var total = 0; for (var i = 11; i <= 15; i++) { var f = this.getField('Question' + i); if (f && f.valueAsString == 'Yes') total++; } event.value = total;
Modify the field prefix ('Question') and the number range (11 to 15) in the script to match your actual field names. Click 'OK', close the properties window, and test your form.

Create, Edit, and Fill PDF Forms Easily with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to easily view, fill out interactive forms, and manage your PDF documents without the need for expensive software.
- 1. Open PDF in WPS: Launch WPS Office and open your interactive PDF form.
- 2. Fill the Form: Click on the form fields to select your 'Yes' or 'No' answers or input text.
- 3. Save and Export: Save your filled form or export it to other formats if needed.

Frequently Asked Questions
Why is my calculation script not updating the total?
Ensure that the calculation order is correct if you have multiple calculated fields. Also, check that your field names exactly match the prefix and numbers defined in the JavaScript code, including case sensitivity.
Can I count 'No' answers instead of 'Yes'?
Yes. You can simply change the condition in the script from f.valueAsString == 'Yes' to f.valueAsString == 'No' to tally the 'No' responses.
How do I handle field names with leading zeros, like Question01 to Question15?
You need to modify your loop to format the number correctly. For example, use a ternary operator like var fname = 'Question' + ((i < 10) ? '0' + i : i); to generate the correct field name string before calling this.getField(fname).




