Calculate Radio Button and Check Box Values in PDF Forms
Question details
The user needs to sum up numeric export values from repeated radio-button or check-box groups in a PDF risk-assessment form and limit the total displayed sum to a maximum of 10.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form for risk assessment that automatically calculates scores based on user selections with a capped maximum value.
- Observed behavior
- The form requires a custom JavaScript calculation to correctly extract export values from mutually exclusive radio buttons and check boxes while applying a logical threshold to the final sum.
Ensure your PDF editing software supports interactive form field creation and custom JavaScript calculations. Open your PDF risk-assessment form in editing mode to access field properties.
Use Parent-Child Naming and Custom JavaScript
This method utilizes hierarchical field naming and JavaScript to efficiently gather selected values and cap the total.
Instead of writing a lengthy script naming every single field individually, using a parent-child field naming structure allows you to group related inputs. This enables the getArray() method to loop through the fields efficiently.
Rename your check boxes and radio buttons using dot notation. For example, instead of naming them riskFactor1a and riskFactor1b, use risk.Factor1a and risk.Factor1b. This groups them logically under the 'risk' parent.
For radio buttons that require a single choice, give them the exact same Group Name (e.g., 'risk').
Right-click each radio button or check box and select Properties. Navigate to the Options tab and enter the specific numeric score for that choice in the 'Export Value' box.
Add a new Text Field where the total will appear. Right-click it, select Properties, and navigate to the Calculate tab. Choose 'Custom calculation script'.
Write your calculation script utilizing the getArray() method to iterate through the 'risk' fields. Ensure correct syntax (like lowercase 'if' and the '+=' assignment operator) to add the values to your total variable.
At the end of your script, before assigning the final value to the event, apply a maximum threshold using JavaScript's Math function: total = Math.min(total, 10). This ensures the displayed result never exceeds 10.
Create Interactive PDF Forms with WPS Office
WPS Office provides robust PDF editing capabilities, allowing you to easily build interactive forms, assign export values to check boxes and radio buttons, and set up advanced calculation scripts.
- 1. Open PDF in Form Mode: Launch your document in WPS Office and navigate to the Form tab to access all interactive elements.
- 2. Insert Check Boxes & Radio Buttons: Click the Check Box or Radio Button icons to place fields into your PDF document.
- 3. Set Export Values: Right-click the inserted field, select Properties, and assign your required numeric export values under the Options tab.
- 4. Apply Calculation Scripts: Add a Text Field for the total, open its Properties, go to the Calculate tab, and enter your custom JavaScript to sum the values.

Frequently Asked Questions
How do I make radio buttons mutually exclusive in a PDF form?
To make radio buttons mutually exclusive, you must give them the exact same Name (group name) but assign a different Export Value to each button in the field properties under the Options tab.
Why is my PDF form custom calculation not updating?
Calculations might not update if the calculation order is incorrect, or if there is a syntax error in your JavaScript. Ensure terms like 'if' are entirely lowercase and check the JavaScript console for specific errors.
What is a parent-child field naming hierarchy in PDFs?
It is a naming convention using dots to organize fields logically (e.g., groupname.itemname). This structure makes it much easier to process multiple fields at once using JavaScript methods like getArray(), rather than referencing each field individually.
Can I hide the calculation total field from printing?
Yes. Open the Properties of the total text field, go to the General tab, and change the Form Field Visibility setting to 'Visible but doesn't print'.




