Change PDF Form Text Color Based on a Checkbox and Number in Adobe Acrobat
Question details
Change a PDF form text field to red or black based on a checkbox state and the field's numeric value.

- Product
- PDF forms in Adobe Acrobat Pro
- Device & OS
- not provided
- Scenario
- A form needs different numeric thresholds depending on whether a checkbox is selected.
- Observed behavior
- The text should be red above 130 when the checkbox is selected, or above 140 when it is not selected; otherwise, it should be black.
Open the form in Adobe Acrobat Pro and identify the exact checkbox field name in Prepare a Form. Make sure Acrobat JavaScript and automatic field calculations are enabled in Preferences.
Add a custom calculation script to the PDF text field
Use this script when the text field must change color automatically according to the checkbox and numeric value.
Open the PDF in Acrobat Pro, then select All tools > Prepare a form. Note the checkbox field name shown in the form editor.
Double-click the target text field, select the Calculate tab, choose Custom calculation script, and click Edit.
Paste the following script and replace CheckBox 1 with the exact checkbox field name: var cb = this.getField("CheckBox 1").valueAsString; var v = Number(event.value); if ((cb != "Off" && v > 130) || (cb == "Off" && v > 140)) { event.target.textColor = color.red; } else { event.target.textColor = color.black; }
Click OK to close the script editor and field properties, save the PDF, and exit form editing. Test values above and at each threshold with the checkbox both selected and cleared.

Work with PDFs and Office documents in WPS Office
WPS Office is a free, lightweight Microsoft Office alternative with a familiar interface for working with Office files and PDFs. Its format compatibility makes it easy to move existing documents; use Acrobat for the conditional PDF form script described above.

Frequently Asked Questions
What happens at exactly 130 or 140?
The script uses greater-than comparisons. With the checkbox selected, 130 stays black; with it cleared, 140 stays black.
How do I find the checkbox field name?
In Acrobat Pro, open All tools > Prepare a form and inspect the checkbox in the form editor. Use its exact field name in this.getField("CheckBox 1").
Why doesn't the color update when I change the checkbox?
In Acrobat Preferences, check that JavaScript and automatic form calculations are enabled. Also confirm that the checkbox field name matches the script and test the form in a viewer that supports Acrobat JavaScript.
Will the script work in every PDF viewer?
No. Some browser and mobile PDF viewers do not support Acrobat form JavaScript. Test the saved form in Adobe Acrobat or Acrobat Reader with JavaScript enabled.




