Automatically Check a PDF Form Checkbox When an Interest Rate Is Entered
Question details
Automatically select a row's checkbox when its interest-rate field contains a nonzero value and clear it when the field is blank or zero.

- Product
- PDF forms
- Device & OS
- not provided
- Scenario
- A PDF form has an interest-rate field and a corresponding checkbox in each row.
- Observed behavior
- Each checkbox should reflect whether its corresponding rate is nonblank and nonzero.
Open the form in a PDF editor that supports editing AcroForm fields and JavaScript, such as Adobe Acrobat Pro. Identify the exact field names for each interest rate and its corresponding checkbox.
Add a validation script to the interest-rate field
Use this method to update a checkbox when the user commits a new value in its corresponding rate field.
The script checks the first widget in the named checkbox field when the rate is a valid, nonzero number. It clears the checkbox for a blank, zero, or nonnumeric value. It accepts a trailing percent sign and a period as the decimal separator.
Form JavaScript must be enabled and supported by the PDF viewer. The checkbox index 0 is suitable for a single checkbox; check the widget index if the field contains multiple checkboxes.
In Adobe Acrobat Pro, open the PDF and choose All tools > Prepare a form.
Double-click the interest-rate field, select the Validate tab, and choose Run custom validation script.
Click Edit and enter this script, replacing Checkbox1 with the exact checkbox field name: var raw = String(event.value == null ? "" : event.value).replace(/^\s+|\s+$/g, ""); var rate = Number(raw.replace(/%$/, "")); var box = this.getField("Checkbox1"); if (box) box.checkThisBox(0, raw !== "" && isFinite(rate) && rate !== 0);
Click OK, repeat the script in each row's rate field using that row's checkbox name, and save the PDF. In Preview, enter a nonzero rate, zero, and a blank value, leaving the field after each entry to commit it.

View PDFs and Work with Office Files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface and compatibility with common Office formats for easier migration. Use its PDF tools for everyday document work; the automatic checkbox script still requires a PDF editor and viewer that support form JavaScript.

Frequently Asked Questions
Why doesn't the checkbox update while I type?
A validation script runs when the rate field value is committed, usually after you leave the field. Enter the rate and press Tab or click another field to test it.
How do I find the checkbox field name?
In Acrobat Pro, choose All tools > Prepare a form, double-click the checkbox, and look for its name in the field properties. Use that exact name in this.getField().
Will the script work in every PDF viewer?
No. The viewer must support AcroForm JavaScript and allow it to run. If a browser viewer does not update the checkbox, test the saved PDF in a JavaScript-capable PDF application.
How do I apply the rule to multiple rows?
Open each interest-rate field's Validate tab and add the script, changing Checkbox1 to the corresponding checkbox field name for that row. Test each row separately.




