PDF Editing Issues

How to Change an Acrobat Text Box Color Based on a Numeric Value

Algirdas JasaitisAlgirdas Jasaitis Nov 3, 2026 869 views

Question details

The user needs to dynamically change the background color of a PDF text field based on the numerical value entered into it using JavaScript.

How to Change an Acrobat Text Box Color Based on a Numeric Value
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating dynamic interactive PDF forms where visual feedback, such as a background color change, is required when a user enters specific numerical values.
Observed behavior
The user wants the text field's fill color to update automatically based on the underlying raw numeric value, rather than the formatted display string.
Before you start

Ensure you have access to the 'Prepare Form' tool in your PDF editor and possess basic familiarity with adding custom JavaScript to form fields.

Solution 1Recommended

Apply a Custom JavaScript Calculation to the Text Field

Use a custom calculation or validation script to evaluate the numeric value of the field and dynamically update its fillColor property.

When dealing with formatted text fields, the PDF engine separates the actual numeric value from the formatted display string. Your JavaScript must evaluate the raw numeric value to trigger the correct background color change.

It is crucial to test your script against various input scenarios, including empty fields, invalid non-numeric entries, positive numbers, and negative numbers, to prevent script errors during data entry.

1
Open the Prepare Form tool

Open your PDF document in Adobe Acrobat and navigate to Tools, then select 'Prepare Form'.

2
Access field properties

Right-click the target text box that requires dynamic formatting and select 'Properties' from the context menu.

3
Add custom calculation script

Navigate to the 'Calculate' tab, select the 'Custom calculation script' radio button, and click the 'Edit' button.

4
Enter the JavaScript code

Type your conditional logic evaluating event.value. For example, use 'if (Number(event.value) < 0) event.target.fillColor = color.red; else event.target.fillColor = color.transparent;'.

5
Save and test

Click 'OK' to save the script, close the properties window, exit form editing mode, and test the field by entering various numeric values.

Apply a Custom JavaScript Calculation to the Text Field
Using Color Arrays: Acrobat JavaScript uses specific color arrays for properties rather than standard HEX codes. You can use predefined arrays like color.red or custom RGB arrays formatted as ["RGB", 1, 0, 0] where values range from 0 to 1.
Easy PDF Editing with WPS

Edit PDFs and Manage Forms Easily with WPS Office

While complex JavaScript is needed for dynamic conditional colors in some editors, WPS Office provides an intuitive PDF editor that lets you easily fill forms, customize text box styles, and manage PDF documents without coding.

  1. 1. Download and open WPS Office: Launch WPS Office and click on the 'PDF' tab from the main dashboard.
  2. 2. Open your PDF document: Import your PDF file and navigate to the 'Form' or 'Edit' tab depending on your required task.
  3. 3. Modify text boxes: Select any text box or form field to instantly access its properties panel and manually adjust background colors, borders, and fonts.
  4. 4. Save the document: Save your newly customized PDF file directly to your local drive or WPS Cloud for easy sharing.
Easily add, edit, and style text boxes and shapes in PDF documents.Full compatibility with standard PDF forms, documents, and Microsoft Office formats.Lightweight application covering Word, Excel, PowerPoint, and PDF editing in one suite.Intuitive user interface that makes formatting PDFs effortless.
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my text box color changing when I type a number?

The script might be reading the formatted text string (like '$1,000') instead of the raw number. Ensure your JavaScript converts the field value to a strict number using Number(event.value) before evaluating the condition.

Can I use standard HTML HEX color codes in my PDF script?

No, Acrobat JavaScript typically uses its own color array format (e.g., ["RGB", r, g, b]) where the RGB values are expressed as fractions between 0 and 1, rather than standard HTML HEX codes or 0-255 integers.

Will this JavaScript color change work on mobile PDF viewers?

Custom JavaScript for dynamic styling is fully supported in robust desktop PDF editors, but many mobile PDF viewers, browsers, and lightweight third-party apps do not fully support complex JavaScript form calculations.