Fix Acrobat Form Field JavaScript Errors for Colors and Save Buttons
Question details
The user needs to apply JavaScript for modifying PDF form field colors and adding a save button, but is encountering an 'event is undefined' error.

- Product
- Adobe Acrobat / Adobe InDesign
- Device & OS
- not provided
- Scenario
- Adding custom JavaScript actions, such as color changes and save functionality, to PDF form fields and buttons.
- Observed behavior
- Running the PDF form script from the InDesign Scripts panel throws an 'event is undefined' error because the code is executing in the wrong application context.
Ensure you are editing the interactive PDF directly in Adobe Acrobat, as form field JavaScript relies on the Acrobat object model and will not execute properly within Adobe InDesign's script panel.
Move JavaScript to the Correct Acrobat Form Event
Placing the script in the specific field event within Acrobat instead of InDesign's application folder resolves the 'event is undefined' error.
InDesign and Acrobat use completely different JavaScript object models. The `event` object only exists when a script is triggered by a specific action inside an interactive PDF, not when executed externally.
Open your interactive PDF document in Adobe Acrobat and navigate to the 'Prepare Form' tool.
Right-click the target field or button and select 'Properties' from the context menu.
Go to the 'Actions' tab. From the 'Select Trigger' dropdown menu, choose the appropriate event, such as 'Mouse Up' for a button click.
Choose 'Run a JavaScript' from the 'Select Action' dropdown and click the 'Add' button.
Paste your JavaScript code into the JavaScript Editor window, click 'OK', and close the properties panel.

Set Form Field Background and Border Colors Dynamically
Use the appropriate Acrobat JavaScript properties to modify the visual appearance of form fields.
Create a Functional Save Button
Assign a specific Acrobat menu command to a button's Mouse Up event to easily trigger the file save action.
Fill and Manage PDF Forms Easily with WPS Office
If you want to avoid dealing with complex JavaScript and confusing scripting panels, WPS PDF offers an intuitive interface to fill out interactive forms, add text, and save documents securely without writing any code.
- 1. Open Your PDF: Launch WPS Office and open your interactive PDF form.
- 2. Access Form Tools: Navigate to the 'Form' or 'Edit' tab on the top ribbon to view all interactive fields.
- 3. Fill in the Data: Click directly on text boxes, checkboxes, or buttons to seamlessly interact with the document.
- 4. Save Instantly: Click the 'Save' icon or press Ctrl+S to save your completed form without needing a custom save button.

Frequently Asked Questions
Why do I get an 'event is undefined' error when running PDF scripts in InDesign?
This happens because InDesign's scripting engine does not recognize Acrobat's specific JavaScript event objects. Form field scripts must be embedded directly into the PDF field's actions in Acrobat to work properly.
Can I remove the red required-field border using JavaScript?
No. The red highlight on required fields is controlled by the user's application preferences in Adobe Acrobat. It cannot be permanently disabled or styled using field-level JavaScript.
How do I bind an onClick event to a PDF button?
In Acrobat, you do not use standard web JavaScript like `document.getElementByName().onClick()`. Instead, you open the button's Properties, go to the Actions tab, select 'Mouse Up' as the trigger, and choose 'Run a JavaScript'.
What is the difference between fillColor and strokeColor?
In Acrobat form JavaScript, `fillColor` determines the background color of the form field, while `strokeColor` controls the color of the field's border outline.




