PDF Editing Issues

How to Include a PDF Form Value in a Total Only When a Checkbox Is Checked

Rana GarciaRana Garcia Nov 3, 2026 869 views

Question details

The user needs to configure a PDF form so that a specific number field is only added to the grand total if a related checkbox is currently checked.

How to Include a PDF Form Value in a Total Only When a Checkbox Is Checked
Product
PDF Form
Device & OS
not provided
Scenario
Creating an interactive PDF form where pricing, scoring, or tallies calculate dynamically based on the options a user selects via checkboxes.
Observed behavior
The total field dynamically updates, adding the paired numeric amount when the checkbox is checked, and excluding it when the checkbox is cleared.
Before you start

Ensure you are using a PDF editor that supports JavaScript form calculations and note down the exact, case-sensitive names of your checkbox and number fields before you begin.

Solution 1Recommended

Use a Custom Calculation Script in the Total Field

Write a short JavaScript snippet in your PDF's Total field properties to read the checkbox state and conditionally add the target number.

In interactive PDF forms, checkboxes return a specific export value when checked and default to 'Off' when cleared. By utilizing a custom calculation script, you can instruct the total field to check this value. If the checkbox is not 'Off', the script fetches the numeric value and includes it in the total.

1
Open the Total Field Properties

Enter the form editing mode in your PDF software. Right-click on the 'Total' text box field and select 'Properties' from the context menu.

2
Enable Custom Calculation

Navigate to the 'Calculate' tab in the Properties dialog box. Select the option labeled 'Custom calculation script'.

3
Enter the JavaScript Code

Click the 'Edit' button to open the JavaScript editor. You will need to write a script that checks the value of your checkbox. For a single checkbox and number field, use a script similar to: var cb = this.getField('YourCheckboxName').value; var num = Number(this.getField('YourNumberFieldName').valueAsString); if (cb !== 'Off') { event.value = num; } else { event.value = 0; }

4
Adjust for Multiple Fields (If Necessary)

If you are summing multiple checkbox/number pairs, repeat the variable assignments for each pair and change the final calculation to add them together (e.g., event.value = num1 + num2).

5
Save and Test

Click 'OK' to save the script, then close the Properties dialog. Exit form editing mode and click the checkbox to verify that the total updates dynamically.

Use a Custom Calculation Script in the Total Field
Important Syntax Check: Field names in PDF JavaScript are strictly case-sensitive. Ensure 'YourCheckboxName' and 'YourNumberFieldName' match your actual form fields perfectly.
Edit Interactive PDF Forms

Manage Advanced PDF Forms with WPS Office

WPS Office offers robust PDF editing capabilities, allowing you to easily insert text fields, manage checkboxes, and apply custom calculation scripts to create dynamic, professional forms.

  1. 1. Open Your Form in WPS Office: Launch WPS Office, open your PDF file, and switch to the 'Form' tab on the top ribbon.
  2. 2. Access Field Properties: Double-click the total field or right-click and choose 'Properties' to access advanced settings.
  3. 3. Apply Calculations: Go to the 'Calculate' section to easily apply basic sums or input your conditional JavaScript.
Easily add, modify, and align interactive form fields like checkboxes and drop-downs.Fully supports custom JavaScript for dynamic calculations and conditional logic.High compatibility with standard Adobe PDF form formats ensuring forms work anywhere.Lightweight, all-in-one suite covering PDF, Word, Excel, and PowerPoint tasks.
QA img-9

Frequently Asked Questions

Why is my PDF total not updating when I click the checkbox?

This usually happens if the calculation order of your PDF form is incorrect, or if the field names referenced in your custom calculation script contain typos. Verify that the field names match perfectly and ensure the total field is set to calculate last.

What is the default export value of a PDF checkbox?

By default, an unchecked box has the value 'Off'. When checked, it returns its designated Export Value, which is commonly 'Yes', 'On', or a specific number depending on how you configured its properties. Checking if the value is strictly not equal to 'Off' is the safest way to verify it is checked.

Can I conditionally add totals without using a JavaScript custom calculation?

No. The standard calculation options (like Sum, Product, or Average) built into most PDF editors apply to all selected fields regardless of a checkbox's state. Conditional logic (adding a value *only if* an action happens) requires a custom JavaScript snippet.

Will this calculation script work when users view the PDF on mobile devices?

It depends heavily on the mobile PDF viewer being used. While robust desktop software like WPS Office and Adobe Acrobat fully support JavaScript, many basic mobile PDF readers or browser plugins block or do not support JavaScript, preventing the total from updating dynamically.