Scope: Acrobat Professional 6.0 and greater
Skill Level: Beginner
Prerequisites: Familiarity with Acrobat Professional
Form-field scripts can be divided into two areas: scripts associated with actions performed on the instance of a field on a page (also called Widget scripts — a specific instance of a field is called a Widget), and scripts associated with the value of a field.
The Widget scripts are for the mouse and field-focus actions performed by the user. The field-value scripts are related to internal actions Acrobat takes when a field value changes. The different types of scripts in each area are listed below.
Widget scripts:
“Mouse Enter” | Runs when cursor enters field |
“Mouse Exit” | Runs when cursor exits field |
“Mouse Up” | Runs when cursor is over field and mouse button is pushed |
“Mouse Down” | Runs when cursor is over field and mouse button is released |
“On Focus” | Runs when field gains keyboard focus |
“On Blur” | Runs when field loses keyboard focus |
Field-value scripts:
“Calculate” | Runs when any field value on the document changes |
“Keystroke” | Runs for each keystroke entered into a text field |
“Validate” | Runs when the associated field value changes |
“Format” | Runs after the Validate script, but only if Validate returns true |
All these scripts are accessed from the Field Properties dialog.
To display the dialog:
1. Activate the Select Object Tool on the Advanced Editing toolbar, Figure 1.
2. Right click on the form field of interest. This action displays a context-popup menu.
3. Select Properties… from the menu. This action activates the Field Properties dialog, Figure 2.
Widget scripts
All field types have an Actions tab on their Properties dialog. This tab provides access to the Widget scripts. The “Select Trigger” pull-down list selects the action that triggers the script, MouseUp, MouseDown and so on. The “Select Action” pull-down list selects the type of action to be performed. For this tip we are only concerned with the “Run a JavaScript” action.
To add a new JavaScript action:
If the field has existing actions, they will be displayed in the Actions window. Figure 2 (above) shows the Properties dialog for a text field with a previously defined “MouseUp” script.
To edit an existing script:
Field-value scripts
Separate tabs are provided on the Field Properties dialog for each of the field-value scripts. Since different types of fields have different types of values, these tabs are different for each field type. For example, the button field does not have any field value scripts since it doesn’t have a value, while the text field uses all the different field scripts. The table below lists the field-value scripts used by each field type.
There are several cases where Acrobat does not provide a user interface for accessing a particular script, yet the field will still run the script if it exists (marked as “No UI”). Acrobat does not provide a user interface because these scripts are not used with the particular field type under normal circumstances. However, this doesn’t mean that these scripts could not be useful, so ambitious users can still set the scripts using a JavaScript function.
Field Type | Format | Keystroke | Validate | Calculate |
Button | X | X | X | X |
Text | Yes | Yes | Yes | Yes |
Check Box | X | No UI (1) | No UI (1) | No UI(1) |
Radio Button | X | No UI (1) | No UI (1) | No UI (1) |
Combo Box | Yes | Yes | Yes | Yes |
List | X | Yes(2) | No UI (1) | No UI (1) |
Signature | Yes(3) | No UI (1) | No UI (1) | No UI (1) |
(1) Acrobat does not provide a user interface to these scripts, but they can be set from the Console Window with the setAction() JavaScript function.
(2) In the List Field the Keystroke script is called the Select Change script.
(3) In the Signature Field the Format script is called the Signed script.
The text field uses all four of the field-value scripts, so we’ll use it as the example in the following discussion.
Format and Keystroke scripts: (both are on the same tab)
In the text field, the Format and Keystroke scripts are used together to enforce formatting. The Keystroke script ensures that only certain keys are entered and the format script adds the final touches when field data is committed.
To access:
1. Open the Field Properties dialog.
2. Select the Format tab.
3. On Select format category, choose “Custom.” This action displays the Format and Keystroke scripts (Figure 3).
4. Push the edit button for either Format or Keystroke to create a new script or edit an existing one.
Validate script:
The Validate script is run when a field value is committed. When users press the Enter key or tab out of the field, they are indicating the entered data should be put into the field value, called “committing” the value. The Validate script sits between the user action that signals the value should be committed (tabbing, pressing Enter or selecting another field) and the actual value being committed.
To access:
Calculate script:
Calculate scripts are run when any field value on the document is changed.
To access:
Related topics: |
PDF Forms, JavaScript |
Top Searches: |
Convert existing forms to fillable PDFs fill and sign any formEdit PDF create PDF Action Wizard |
Try Acrobat DC
Get started >
Learn how to
edit PDF.
Post, discuss and be part of the Acrobat community.
Join now >
0 comments
Comments for this tutorial are now closed.
Comments for this tutorial are now closed.