PDF Editing Issues

How to Toggle a Checkbox When Two PDF Form Fields Match

Huda QurayshiHuda Qurayshi Nov 2, 2026 868 views

Question details

The user needs a script to automatically check a box in a PDF form when the numeric values of two specific calculated fields are equal.

How to Toggle an Acrobat Checkbox When Two Fields Match
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating dynamic PDF forms where visual indicators, such as a checkbox, automatically update based on the calculation results of other form fields.
Observed behavior
The user needs the exact JavaScript syntax and logic to accurately compare two numeric fields and set the checkbox state accordingly rather than using plain text outputs.
Before you start

Ensure you have the exact field names for the two calculated source fields and the target checkbox in your PDF form before applying the script.

Solution 1Recommended

Apply JavaScript to Validate and Toggle the Checkbox

Use a custom calculation script on the checkbox or an invisible field to compare the two numeric fields.

Instead of using string values like 'Yes' or 'No', a checkbox in PDF forms requires a specific widget state assignment. Converting the field values to numbers ensures an accurate mathematical comparison before passing the result to the checkbox.

1
Open form properties

Open your PDF form in Adobe Acrobat and enter 'Prepare Form' mode. Right-click the target checkbox (e.g., named 'match') and select 'Properties'.

2
Access calculation settings

Navigate to the 'Calculate' tab in the Properties window and select the 'Custom calculation script' option.

3
Enter the JavaScript

Click 'Edit' and enter the following JavaScript: var a = Number(getField("numbertot").value); var b = Number(getField("numbertotal").value); getField("match").checkThisBox(0, a === b ? 1 : 0);

4
Test the form

Click 'OK' and 'Close'. Exit form editing mode and test the form by entering matching and non-matching numeric values into the source fields.

Apply JavaScript to Validate and Toggle the Checkbox
Field Name Verification: Make sure to replace 'numbertot', 'numbertotal', and 'match' in the script with the exact field names used in your specific PDF document.
Comprehensive PDF Editor

Edit and Fill PDF Forms Seamlessly with WPS Office

While complex JavaScript might require specialized scripting tools, you can easily create, edit, fill, and sign interactive PDF forms using WPS Office's built-in PDF editor. It provides a straightforward interface that handles your daily PDF form requirements effortlessly.

  1. 1. Open your document: Launch WPS Office and open your PDF document using the built-in PDF reader.
  2. 2. Access the Form tools: Navigate to the 'Form' tab on the top ribbon to view available interactive form options.
  3. 3. Fill or modify fields: Use the intuitive tools to click on checkboxes, fill in text fields, or add new interactive elements to the document.
  4. 4. Save and export: Save the completed PDF form or export it directly to share with colleagues or clients.
Easily fill interactive PDF forms, including checkboxes and text fieldsFully compatible with standard Adobe PDF formatsAdd digital signatures, text, and annotations securelyLightweight, fast, and user-friendly interface for all devices
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my checkbox updating when the fields match?

This usually happens if the source fields are treated as text strings rather than numbers. Ensure you wrap the field values with the Number() function in your JavaScript so they are properly compared as numerical values.

Can I use 'Yes' and 'No' to set a checkbox state?

No, PDF checkboxes use specific widget states rather than text strings. You should use the checkThisBox(widgetIndex, boolean) method, applying 1 for checked and 0 for unchecked, instead of assigning text values.

Do I need to trigger the script manually every time the numbers change?

No. If you place the script in the custom calculation event of the checkbox or another calculated field, Acrobat's calculation sequence will automatically trigger it whenever the referenced source fields are updated.