PDF Editing Issues

Fix Acrobat Form Field JavaScript Errors for Colors and Save Buttons

Steven ParkerSteven Parker Oct 28, 2026 869 views

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.

How to Fix Acrobat Form Field JavaScript Errors for Colors and Save Buttons
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Prepare Form Mode

Open your interactive PDF document in Adobe Acrobat and navigate to the 'Prepare Form' tool.

2
Access Field Properties

Right-click the target field or button and select 'Properties' from the context menu.

3
Select the Trigger Action

Go to the 'Actions' tab. From the 'Select Trigger' dropdown menu, choose the appropriate event, such as 'Mouse Up' for a button click.

4
Add the JavaScript

Choose 'Run a JavaScript' from the 'Select Action' dropdown and click the 'Add' button.

5
Paste and Save Code

Paste your JavaScript code into the JavaScript Editor window, click 'OK', and close the properties panel.

Move JavaScript to the Correct Acrobat Form Event
Context is Key: Ensure that your code strictly references Acrobat's JavaScript API parameters rather than InDesign script logic.

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. 1. Open Your PDF: Launch WPS Office and open your interactive PDF form.
  2. 2. Access Form Tools: Navigate to the 'Form' or 'Edit' tab on the top ribbon to view all interactive fields.
  3. 3. Fill in the Data: Click directly on text boxes, checkboxes, or buttons to seamlessly interact with the document.
  4. 4. Save Instantly: Click the 'Save' icon or press Ctrl+S to save your completed form without needing a custom save button.
Easily fill, edit, and sign interactive PDF forms without complex scripting.Fully compatible with standard PDF formats and Microsoft Word, Excel, and PowerPoint files.Lightweight application that loads large forms and documents instantly.Cross-platform support ensures your forms work smoothly on Windows, Mac, and mobile devices.
microsoft office alternative - wps office

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.