How to Count Radio Button Selections by Value in a PDF Form
Question details
The user needs to calculate the total number of times specific ratings (e.g., values 1 to 5) are selected across multiple radio button groups in a PDF assessment form.

- Product
- Adobe Acrobat / PDF Forms
- Device & OS
- not provided
- Scenario
- Creating an interview assessment or survey form where responses need to be aggregated by specific rating values.
- Observed behavior
- A script or automated method is required to check multiple radio button groups and count how many times each specific export value is selected, displaying the total in another field.
Before applying the script, ensure you have recorded the exact names of all the radio button groups you want to include in the calculation, and verify the export values assigned to each radio button option.
Use a Custom Calculation Script in the Total Field
Use a custom JavaScript snippet in the calculation tab of a text field to iterate through specified radio button groups and count matching values.
This method requires you to create a separate text field for each rating value you want to total (e.g., one field for the 'Rating 1' total, another for the 'Rating 2' total). The script will loop through the designated fields and increment the count when the value matches your criteria.
Insert a new Text Field in your PDF form where the total count will be displayed (e.g., name it 'TotalRating1').
Right-click the newly created text field, select 'Properties', and navigate to the 'Calculate' tab.
Select the 'Custom calculation script' radio option and click the 'Edit' button.
Paste the following script: `var fields=["Group1","Group2"]; var total=0; for(var i in fields){var f=this.getField(fields[i]); if(f.valueAsString=="1") total++;} event.value=total;`
Replace 'Group1' and 'Group2' with your actual radio button group names. Change '1' in `f.valueAsString=="1"` to the specific rating value you want to count for this specific total field. Click 'OK' to save.

Alternative: Use Numeric Text Fields Instead of Radio Buttons
If writing custom scripts for numerous radio buttons is too complex, consider replacing radio button groups with text fields configured to accept only numbers within a specific range.
Create and Calculate PDF Forms Effortlessly with WPS Office
WPS Office provides robust PDF editing capabilities, allowing you to easily insert interactive form fields, manage properties, and apply custom calculation scripts just like Adobe Acrobat.
- 1. Open Your PDF: Launch WPS Office and open your PDF assessment form.
- 2. Access Form Tools: Navigate to the 'Form' tab to access interactive form controls like Text Fields and Radio Buttons.
- 3. Apply Calculation Scripts: Double-click any text field to open its properties, switch to the 'Calculate' tab, and select 'Custom calculation script' to input your JavaScript.

Frequently Asked Questions
Why is my calculation script not updating immediately when a radio button is clicked?
Form calculations often update sequentially or when a field loses focus. Ensure your field calculation order is correctly set in the form properties, or try checking the 'Commit selected value immediately' option in the Options tab of your radio button properties.
Can I use this script to count multiple values in the same total field?
Yes, you can modify the `if` condition using the logical OR operator (`||`). For example, `if(f.valueAsString=="1" || f.valueAsString=="2")` will count occurrences where either a 1 or a 2 was selected.
Where do I find the export value of a radio button?
Right-click the radio button in form editing mode, select 'Properties', and go to the 'Options' tab. The 'Radio Button Choice' or 'Export Value' field displays the value that the calculation script checks against.
Does WPS PDF support custom JavaScript for form calculations?
Yes, the WPS Office PDF editor supports JavaScript for form calculations, allowing you to use standard PDF custom scripts to count radio button selections and automate form behavior.




