How to Calculate Values Using Acrobat JavaScript for Multiple Checkboxes
Question details
The user needs to write a custom Acrobat JavaScript calculation script that conditionally divides different pairs of text fields depending on which specific combination of multiple checkboxes is currently selected.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form that requires dynamic mathematical operations based on user checkbox input.
- Observed behavior
- The form needs logic to check checkbox states and perform specific division operations for specific pairs, while returning zero for any other unmatched combinations.
Ensure you have the 'Prepare Form' tool enabled in your PDF editor and that all target text fields and checkboxes are correctly named before applying your JavaScript code.
Use a Custom Calculation Script with valueAsString Properties
By verifying the valueAsString property of each checkbox, you can determine if a specific pair is active and execute the targeted field division while defaulting to zero otherwise.
When working with Acrobat JavaScript, checkboxes return an 'Off' string when unchecked and a defined export value when checked. By reading these string values alongside the target input fields, you can use standard conditional statements to route the calculation logic.
This approach guarantees that if an invalid combination of checkboxes is selected, or if the required input fields are empty, the script gracefully defaults to a zero value to prevent calculation errors in your PDF form.
Open your PDF form document in Adobe Acrobat, navigate to the Tools menu, and select the Prepare Form tool to make the fields editable.
Right-click the target text field where you want the final calculated result to appear and select Properties from the context menu.
Navigate to the Calculate tab in the Properties dialog box and select the 'Custom calculation script' option.
Click the Edit button and input the script to define variables for your checkboxes and numeric fields. Use this.getField("checkbox_name").valueAsString to get the checkbox status and Number(this.getField("field_name").value) to get the numeric inputs.
Add an if/else block to check if the first pair of checkboxes is not 'Off' (e.g., c1 != 'Off' && c2 != 'Off') while ensuring the second pair is 'Off'. Within this block, set event.value = f1 / f2.
Add an else if block for the opposite scenario to calculate f3 / f4. Finally, add a trailing else block to set event.value = 0 to handle all other unmatched combinations.

Fill and Manage Interactive PDF Forms with WPS Office
While advanced script authoring requires a dedicated script editor, WPS Office offers a highly capable and user-friendly PDF editor. You can seamlessly open, fill out, and manage complex interactive PDF forms containing built-in calculations without any hassle.
- 1. Install WPS Office: Download and install WPS Office on your desktop or mobile device.
- 2. Open your PDF form: Launch WPS PDF and open the interactive PDF form you need to fill out.
- 3. Interact with the fields: Click on the highlighted form fields to enter your data or tick the necessary checkboxes. Pre-configured calculations will update automatically.
- 4. Save your progress: Once completed, save the filled document locally or share it directly from the WPS interface.

Frequently Asked Questions
Why does my Acrobat JavaScript calculation return an error when a field is empty?
If input fields are empty, dividing by zero or a null value can cause a script exception. Ensure your script validates that the numeric field values are not empty strings before attempting to perform the division.
How do I find the correct export value for a PDF checkbox?
You can find a checkbox's export value by right-clicking it, selecting Properties, and looking under the Options tab. If the user leaves it unchecked, its valueAsString property will strictly return 'Off'.
Can I use this custom calculation script for multiplication or addition instead?
Yes. You can easily modify the mathematical operator assigned to event.value. Simply replace the division symbol (/) with an asterisk (*) for multiplication or a plus sign (+) for addition in your custom code.
Does WPS PDF support automatic interactive form calculations?
Yes, WPS PDF comprehensively supports interacting with standard PDF forms. It automatically processes and displays the results of built-in form calculations when you input data into designated fields.




