Change PDF Button Color with JavaScript in Adobe Acrobat
Question details
The user wants to know how to use JavaScript to change or toggle the fill color of an interactive PDF button upon clicking it.

- Product
- Adobe Acrobat / PDF
- Device & OS
- not provided
- Scenario
- Customizing interactive PDF form elements with JavaScript to create dynamic visual feedback when a user clicks a button.
- Observed behavior
- The user needs the correct JavaScript syntax and event triggers to modify the fillColor property of a button or another form field.
Ensure your PDF document is opened in form editing mode and that you have access to the JavaScript editor in your PDF application. Note that not all third-party PDF viewers support advanced JavaScript execution.
Set a Direct Fill Color Using JavaScript
Use a simple script applied to the Mouse Up event to permanently change the button's color when clicked.
This method is ideal when you want an element to permanently change to a specific color after a user interacts with it to indicate completion or selection.
Open the PDF in form editing mode, right-click the target button, and select 'Properties' from the context menu.
Navigate to the 'Actions' tab within the Properties dialog. Set the 'Select Trigger' dropdown to 'Mouse Up'.
From the 'Select Action' dropdown, choose 'Run a JavaScript' and click the 'Add' button.
In the JavaScript Editor window, type the following code: event.target.fillColor = color.red; then click 'OK' to save and close the dialogs.

Toggle Between Two Colors on Click
Use a conditional script to make the button switch back and forth between two distinct colors each time it is clicked.
Customize PDF Forms Easily with WPS Office
WPS PDF provides an intuitive interface for creating, editing, and managing interactive PDF forms. You can easily modify button appearances and properties without always needing complex scripting.
- 1. Open PDF in WPS Office: Launch WPS Office and open your PDF document containing the interactive forms.
- 2. Access the Form Tab: Navigate to the 'Form' tab on the top ribbon menu to reveal the form editing tools.
- 3. Edit Button Properties: Click on an existing button or insert a 'Push Button'. Double-click the button to open its properties panel.
- 4. Adjust Appearance: Modify the appearance settings, including borders, fill colors, and text, directly from the visual interface without writing code.

Frequently Asked Questions
Can I use JavaScript to change the color of another field instead of the button clicked?
Yes, you can change the color of a different form field by referencing its specific field name. Instead of using 'event.target.fillColor', you would use a script like 'this.getField("YourTargetFieldName").fillColor = color.blue;'.
Why isn't the PDF button color changing when I click it?
This typically occurs if JavaScript execution is disabled in your specific PDF viewer's security settings, if there is a syntax error in your script, or if you are viewing the PDF in a browser-based reader that doesn't support advanced Acrobat JavaScript.
What are the standard color names supported in Acrobat JavaScript?
The standard color array includes color.transparent, color.black, color.white, color.red, color.green, color.blue, color.cyan, color.magenta, and color.yellow. You can also define custom RGB colors using arrays, such as ['RGB', 1, 0.5, 0].
Why is 'Mouse Up' recommended over 'Mouse Down' for button actions?
'Mouse Up' is the standard behavior for user interfaces because it allows the user to change their mind. If they press the mouse button down but decide not to execute the action, they can move their cursor off the button before releasing it, safely canceling the click.




