How to Auto-Check PDF Form Checkboxes Based on a Numeric Value
Question details
The user wants to automatically select specific PDF checkboxes depending on whether a calculated numerical value (such as an average) is above or below a certain threshold.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms with conditional logic for checkboxes based on calculated totals or averages.
- Observed behavior
- The user needs to apply JavaScript to read a 'Total' field and toggle the state of 'Yes' or 'No' checkboxes accordingly.
Ensure your PDF form fields are correctly named and that you have access to the JavaScript editor in your PDF application. Verify the exact export values for your checkboxes in their properties menu.
Use a Custom JavaScript Calculation to Toggle Checkboxes
Apply a custom JavaScript calculation script to the relevant field to read the total value and automatically check or uncheck the corresponding checkboxes.
In interactive PDF forms, checkboxes can be controlled dynamically using JavaScript. By reading the value of a total or average field, you can set the export value of a target checkbox to essentially 'check' it when a condition is met.
Open your PDF document in Edit mode and locate the field where the average or total is calculated (e.g., the 'Total' field).
Right-click the calculation field, select 'Properties,' and navigate to the 'Calculate' tab.
Select the 'Custom calculation script' option and click the 'Edit' button to open the JavaScript editor.
Input the following script: var n = Number(this.getField("Total").value); var yes = this.getField("checkYes"); var no = this.getField("checkNo"); if (n > 2.4) { yes.value = "Yes"; no.value = "Off"; } else { yes.value = "Off"; no.value = "Yes"; }
Open the properties of your target checkboxes (named 'checkYes' and 'checkNo' in the script). Go to the 'Options' tab and confirm that their export values exactly match the string used in the script (e.g., 'Yes').

Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides a robust PDF editor that allows you to create, edit, and fill interactive PDF forms effortlessly. Whether you need to add checkboxes, text fields, or manage form data, WPS PDF offers a user-friendly and highly compatible alternative for all your document needs.
- 1. Open your PDF: Launch WPS Office and open your PDF document using the built-in WPS PDF editor.
- 2. Navigate to the Form tab: Click on the 'Form' tab located in the top ribbon to access all interactive form controls.
- 3. Insert form controls: Select 'Check Box', 'Text Field', or other necessary form controls and click on the document to insert them.
- 4. Adjust properties: Double-click any inserted form field to adjust its properties, appearance, and specific export values to meet your requirements.

Frequently Asked Questions
Why isn't my PDF checkbox updating when the total field changes?
This usually happens if the calculation order of your form fields is incorrect, or if the export values specified in your JavaScript do not exactly match the export values configured in the checkbox's 'Options' tab.
How do I find the exact name of a PDF form field?
In form editing mode, the names of the fields are usually displayed directly over the field boxes. You can also right-click the field and select 'Properties' to view, copy, or change its exact name.
Can I use this JavaScript for more than two checkboxes?
Yes. You can expand the if/else logic in your JavaScript to define variables for additional checkboxes, setting their values to their respective export values or 'Off' based on your custom conditions.




