How to Highlight Empty PDF Form Fields and Clear Color After Entry
Question details
The user wants to apply a specific highlight color to empty form fields in a PDF to guide user input, and have that highlight color automatically removed or changed to white once the field is populated.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form where mandatory or empty text fields need to stand out visually until the user fills them in.
- Observed behavior
- By default, PDF form fields do not dynamically change background colors based on their input value, requiring a custom script to trigger the visual change.
Ensure you are opening your document in a professional PDF editor (like Acrobat or WPS PDF) that supports interactive form creation and JavaScript custom calculation scripts.
Use a Custom Calculation Script to Change Field Fill Color
Apply a simple JavaScript condition in the form field's properties to check if the field is empty, applying a background color if true, and switching to white if false.
Interactive PDF forms allow the use of JavaScript to dynamically adjust field properties. By attaching a script to the calculation event of a text field, the document can continuously monitor the field's value and update its appearance automatically.
The script uses RGB values mapped between 0 and 1, so traditional 0-255 RGB values must be divided by 255.
Open your PDF document in your advanced PDF editor and navigate to the Form or Prepare Form tool to reveal all interactive fields.
Right-click the specific text field you want to modify and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Calculate' tab to set up automated actions for this specific field.
Select the option for 'Custom calculation script' and click the 'Edit' button. Paste the following code: event.target.fillColor = (event.value == "") ? ["RGB", 170/255, 191/255, 255/255] : color.white;
Click 'OK' to save the script, close the properties window, and exit form editing mode. Click on the field and type a value to see the highlight clear automatically.

Create and Manage Interactive PDF Forms with WPS PDF
WPS PDF provides a comprehensive suite of form editing tools, allowing you to easily insert text fields, checkboxes, and modify properties without needing heavy or expensive software.
- 1. Open your PDF: Launch WPS Office and open your PDF document.
- 2. Access Form tools: Navigate to the 'Form' tab located in the top ribbon menu.
- 3. Insert form elements: Click on 'Text Field' or other interactive form controls to place them onto your document.
- 4. Adjust properties: Double-click the inserted field to modify its appearance, name, and background color settings.
- 5. Save the form: Save your document to finalize the interactive fields for users to fill out.

Frequently Asked Questions
Can I use this script for checkboxes or radio buttons?
While the logic is similar, checkboxes and radio buttons use different value states (like 'Off' or 'Yes') rather than an empty string (""). The script provided is specifically optimized for text input fields.
Why is the color not updating immediately when I type?
If the color only updates after you click outside the text field, this is normal behavior. Calculation scripts typically trigger when a field loses focus or the value is officially committed.
How do I apply this to multiple fields at once?
To apply the script to multiple fields, you must open the properties for each text field individually and paste the custom calculation script into each one's Calculate tab.
Will this script work on mobile PDF readers?
It depends on the specific mobile PDF reader. While desktop PDF editors fully support JavaScript calculations, many basic mobile PDF viewers disable JavaScript execution for security or performance reasons.




