How to Display a Conditional Sum When a PDF Checkbox Is Selected
Question details
The user needs to calculate and display the sum of several numeric fields in a PDF form strictly when a specific check box is ticked.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form that requires dynamic math calculations dependent on a user's checkbox selection.
- Observed behavior
- The total field needs to remain blank or zero until the user explicitly selects a checkbox to trigger the addition of target numeric fields.
Verify the exact field names for your checkbox and numeric fields, and ensure you are using a PDF editor with advanced form properties that support custom JavaScript.
Use a Custom Calculation Script in Form Properties
Add a JavaScript condition to the total field to check the state of the checkbox before executing the sum calculation.
Interactive PDF forms use JavaScript to handle conditional logic. By checking the export value of the checkbox (which defaults to 'Off' when unchecked), you can instruct the total text field to either sum up specific fields or return a blank value.
Open your PDF form in editing mode. Right-click the 'Total' text field where you want the sum to appear and select 'Properties'.
In the Properties dialog box, click on the 'Calculate' tab at the top and select the 'Custom calculation script' option.
Click the 'Edit' button and enter a script evaluating the checkbox. Example: `if (this.getField("Check Box 1").value !== "Off") { event.value = this.getField("Store 1").value + this.getField("Store 2").value; } else { event.value = ""; }`
Replace the placeholder field names with your actual field names, click 'OK' to save the script, and close the properties window. Toggle the checkbox to verify the calculation works.

Create and Edit Interactive PDF Forms with WPS PDF
WPS Office provides robust PDF editing capabilities, empowering you to effortlessly insert text fields, checkboxes, and apply advanced calculations to make your PDF forms dynamic.
- 1. Open the PDF File: Launch WPS Office, switch to the PDF module, and open your form document.
- 2. Access Interactive Form Tools: Navigate to the 'Form' tab on the top ribbon to view available interactive elements.
- 3. Insert Form Fields: Use the 'Text Field' and 'Check Box' options to build your layout and assign names to each field.
- 4. Configure Field Properties: Double-click your target result field to access properties, navigate to the Calculate settings, and define your sum or conditional rules.

Frequently Asked Questions
Can I calculate a sum in a PDF without using JavaScript?
Yes, for a basic sum, you can use the built-in 'Value is the sum of the following fields' option in the Calculate tab of the field properties. However, making it conditional (triggering only when a checkbox is selected) strictly requires a custom JavaScript calculation.
What is the default export value of a PDF checkbox?
By default, a checked box returns an export value of 'Yes', and an unchecked box returns 'Off'. You can verify or customize the 'Yes' value by checking the 'Options' tab in the checkbox properties.
Why is my PDF form calculation not updating automatically?
This usually happens due to calculation order issues or software preferences. Ensure that 'Calculate fields automatically' is enabled in your PDF editor's preference settings, and check that the target fields are ordered correctly in the form field panel.




