How to Dynamically Get Triggering Field Names in Acrobat JavaScript
Question details
The user needs a dynamic method to identify which form button or field triggered a JavaScript action without hardcoding the field names in the script.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Writing scalable, reusable document-level JavaScript for PDF forms to handle interactive events like mouse clicks.
- Observed behavior
- Developers often hardcode field names or mistakenly use event.source (which returns null for non-calculation events), leading to inefficient scripts and errors when managing multiple interactive buttons.
Before modifying document-level scripts, ensure you have sufficient permissions to edit interactive form fields in your PDF editor and that JavaScript execution is enabled in your security preferences.
Use event.target.name for Interactive Events
Utilize the event object's target property to dynamically capture the name of the specific object that triggered an interactive click or mouse event.
In PDF JavaScript, the 'event.target' property refers to the target object that triggered the current event. By accessing 'event.target.name', you can dynamically retrieve the name of the field or button being clicked, allowing you to create universal functions without hardcoding field names.
Open your PDF form in editing mode and navigate to the JavaScript or Document-Level Scripts management section.
Add a new script containing your dynamic function. For example: function catchAll() { app.alert(event.target.type + ': ' + event.target.name); }
Open the properties of any button or field, go to the Actions tab (e.g., Mouse Up event), and simply add the code: catchAll();

Avoid Using event.source for Button Clicks
Understand the distinction between calculation triggers and interaction triggers to prevent null reference errors in your PDF scripts.
Manage PDF Forms Easily with WPS Office
While advanced JavaScript debugging requires heavy, specialized tools like Adobe Acrobat, WPS Office offers a free, lightweight, and highly compatible alternative for handling daily PDF form tasks. With its familiar UI, you can seamlessly view, fill, and manage interactive PDF documents alongside your Word, Excel, and PowerPoint files.
- 1. Download and Install: Visit the official WPS website to download and install the free, lightweight WPS Office suite.
- 2. Open Your Document: Launch WPS PDF and open your interactive PDF form.
- 3. Fill and Save: Easily fill out form fields, highlight text, and save your document with full formatting preserved.

Frequently Asked Questions
Why does event.source return null when clicking a PDF button?
The 'event.source' property is exclusively reserved for calculation events. When you click a button (like a Mouse Up action), it triggers an interaction rather than a calculation, causing 'event.source' to return null.
Can I use document-level JavaScript to manage multiple PDF form buttons?
Yes, you can write a single document-level function utilizing 'event.target.name' and call this function from multiple buttons. This eliminates the need to rewrite or hardcode specific field names inside every individual button's script.
How do I identify the specific type of field triggering the event?
You can use the 'event.target.type' property alongside 'event.target.name' in your JavaScript. This dynamically identifies whether the object interacting with your script is a button, a text field, or a checkbox.
Are JavaScript event properties the same across all PDF readers?
While standard event properties like 'event.target' are widely supported in advanced editors like Adobe Acrobat, some basic or lightweight PDF readers may have limited JavaScript engine support, which can prevent interactive form scripts from executing properly.




