Apply the Same On Blur Script to All Acrobat PDF Form Fields
Question details
Apply the same custom On Blur JavaScript action to multiple PDF form fields.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A form creator wants multiple fields to run the same script when a user moves focus away from a field.
- Observed behavior
- The form creator needs a way to assign the action because default field properties do not include actions.
Create the form fields first in Acrobat Pro and make sure Acrobat JavaScript is enabled in Preferences. Decide which fields should receive the action, as assigning a new On Blur action replaces any existing action for that trigger.
Assign an On Blur action with the Acrobat JavaScript console
Use a console script to apply the same action to the form fields already in the PDF.
Acrobat does not generally let you set an On Blur action as the default for every newly created field. Run the assignment again for fields added later.
Open the PDF in Acrobat Pro, then open the JavaScript console from All tools > Use JavaScript > JavaScript debugger. The menu name may vary by Acrobat version.
In the console, enter this example, replacing the text inside blurScript with your own JavaScript: var blurScript = "console.println('Blur: ' + event.target.name);"; for (var i = 0; i < this.numFields; i++) { var field = this.getField(this.getNthFieldName(i)); if (field) field.setAction('OnBlur', blurScript); }
Select the complete script in the console and execute it. In Windows, you can press Ctrl+Enter. The loop assigns the action to every field it retrieves; modify it to filter field names if only some fields should receive the action.
Choose File > Save, then interact with several fields and move focus away from each one. With the example action, check the JavaScript console for the field names.

Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface for working with documents, spreadsheets, presentations, and PDFs. Its Microsoft Office format compatibility makes it easier to migrate existing files. Use Acrobat for assigning the JavaScript form actions described above.

Frequently Asked Questions
Can I make an On Blur action the default for new Acrobat fields?
Acrobat does not generally include actions in the default properties applied to new fields. Create the fields first, then assign the action with a script.
Will the script overwrite existing field actions?
The setAction('OnBlur', ...) call replaces the existing On Blur action on each affected field. Review existing actions in Prepare a form before running the script.
How can I apply the action to only some fields?
Modify the console loop to check each field name before calling setAction. For example, apply the action only when the name starts with a prefix used by the target fields.
Why doesn't the action run in another PDF viewer?
PDF viewers vary in their support for Acrobat JavaScript and form actions. Test the saved form in the viewer your recipients will use and check whether JavaScript is enabled.




