How to Calculate Values from Multiple PDF Checkbox Selections
Question details
The user wants to assign and display a specific value in a PDF form text field based on the combination of row and column checkboxes selected from a fixed matrix.

- Product
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form that requires pricing or value matrix calculations based on a user's checkbox selections.
- Observed behavior
- Needs a JavaScript method to read the states of multiple checkboxes and output the corresponding matrix value into a destination field.
Ensure you are using a PDF editor that supports form field properties and JavaScript calculations, and note down the exact, case-sensitive names of your checkbox fields before writing the script.
Use Custom Calculation Scripts in Destination Fields
Assign a conditional JavaScript calculation to the destination text field to check the state of the checkboxes and populate the correct matrix value.
Instead of placing the script in the checkboxes themselves, it is best practice to place a conditional custom calculation script in each destination field that needs to be populated.
Open the properties of your destination text field, navigate to the Format tab, and set the format category to Number with your preferred currency symbol.
Go to the Calculate tab in the field properties, select 'Custom calculation script', and click the 'Edit' button to open the JavaScript editor.
Use the getField() method to retrieve the current state of each checkbox. For example: var single = this.getField("Single").value; var ins1 = this.getField("Insurance 1").value;
Write an IF statement to check that the required checkboxes are not in the 'Off' state. For example: if (single !== "Off" && ins1 !== "Off") { event.value = 10; } else { event.value = ""; }
Repeat this script setup for each destination field in your matrix, making sure to update the checkbox field names and the event.value to match the correct row and column combination.

Create and Manage PDF Forms Easily with WPS PDF
WPS Office provides comprehensive PDF editing tools, allowing you to design interactive forms, insert checkboxes, and manage form fields efficiently without advanced technical knowledge.
- 1. Open your PDF form: Launch WPS Office and open your interactive PDF document.
- 2. Access the Form tools: Navigate to the 'Form' tab in the top ribbon to access PDF form creation and editing tools.
- 3. Insert form fields: Click on 'Text Field', 'Check Box', or other form controls to add them directly to your document.
- 4. Edit field properties: Double-click any form field to modify its properties, appearance, and format settings.

Frequently Asked Questions
Why does my PDF calculation script return an error?
Errors usually occur due to syntax mistakes or incorrect field names. Verify that your field names in the this.getField() method match your actual form fields exactly, as JavaScript is case-sensitive.
Can I put the calculation script directly into the checkbox?
While technically possible, it is not recommended. Placing the script in the destination field's custom calculation tab ensures the value updates dynamically and accurately whenever the dependent checkboxes change states.
How do I clear the destination field if a checkbox is unselected?
Use an 'else' statement in your custom calculation script to set event.value = "". This ensures the destination field is automatically cleared when the required checkbox combination is no longer met.
Do these JavaScript calculations work on all PDF viewers?
No, not all basic PDF viewers or browser-based PDF readers support JavaScript calculations. For the best compatibility, users should fill out the form using robust PDF software like Adobe Acrobat or WPS Office.




