How to Change Text Field Color When a Checkbox is Selected in Acrobat
Question details
The user wants to conditionally change the background color of a specific text field in a PDF form when a linked checkbox is checked or unchecked.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where text fields dynamically highlight or change color based on user selections in checkboxes.
- Observed behavior
- The user needs the correct JavaScript syntax and placement instructions to trigger the color change on selection and revert it when the checkbox is cleared.
Ensure your PDF form already contains both the checkbox and the text field you wish to link, and accurately note down their exact field names as JavaScript is case-sensitive.
Use JavaScript in the Checkbox Mouse Up Event
Adding a custom JavaScript action to the checkbox properties allows the text field color to evaluate and update immediately when the user interacts with it.
To achieve a dynamic color change without relying on toggling the current state, you should evaluate the explicit value of the checkbox. The script is best placed in the Mouse Up event or the Validate event so that it triggers exactly when the user's click is completed.
Enter 'Prepare Form' mode in Adobe Acrobat. Right-click the target checkbox and select 'Properties' from the context menu.
In the Checkbox Properties window, click on the 'Actions' tab. Under 'Select Trigger', choose 'Mouse Up'.
Under 'Select Action', choose 'Run a JavaScript' from the dropdown menu, then click the 'Add...' button to open the JavaScript Editor.
Paste the following script into the editor: var target = this.getField('TextFieldName'); var checkbox = event.target; target.fillColor = checkbox.value !== 'Off' ? color.red : color.white; Replace 'TextFieldName' with the actual name of your text field. Change 'color.red' or 'color.white' to your preferred colors.
Click 'OK' to close the editor, then click 'Close' on the Properties window. Exit 'Prepare Form' mode and click the checkbox to verify the text field changes color correctly.

Manage and Fill PDF Forms Smoothly with WPS Office
If you frequently work with interactive PDF forms, WPS Office provides a robust, lightweight, and highly compatible PDF editor. It allows you to seamlessly fill out complex forms, view interactive elements, and manage your documents without heavy system resource usage.
- 1. Download and Install: Download WPS Office for free from the official website and complete the installation on your device.
- 2. Open Your PDF Form: Launch WPS Office, click on 'Open', and select your interactive PDF document from your local files.
- 3. Interact with Form Fields: Navigate to the 'PDF' tab. You can directly click on checkboxes and type into text fields just like you would in Acrobat.
- 4. Save Your Changes: Once the form is filled or modified, click the 'Save' icon or press Ctrl+S to save your completed PDF.

Frequently Asked Questions
How do I change the text color instead of the background color?
To change the actual text color rather than the background, replace 'target.fillColor' with 'target.textColor' in your JavaScript code. For example: target.textColor = checkbox.value !== 'Off' ? color.red : color.black;
Why isn't my JavaScript running when I click the checkbox?
Make sure JavaScript is enabled in your PDF viewer. In Acrobat, go to Edit > Preferences > JavaScript, and ensure 'Enable Acrobat JavaScript' is checked. Also, verify that the field names in your script perfectly match the names in your form, including capitalization.
Can I use custom hex colors in Acrobat JavaScript?
Yes. Instead of using predefined colors like 'color.red', you can define custom RGB or CMYK colors. For RGB, you can define it using an array like ['RGB', 1, 0.5, 0], where the values range from 0 to 1 rather than 0 to 255.
What is the difference between Mouse Up and Mouse Down triggers?
The 'Mouse Down' event triggers the moment you press the mouse button, while 'Mouse Up' triggers when the button is released. Using 'Mouse Up' is generally recommended for form interactions because it allows the user to cancel the action by dragging their cursor away before releasing the click.




