6
Using Acrobat JavaScript in Forms
Forms Essentials
Highlighting Required Form Fields
Some text fields on a form may not be left blank: these are called required form fields. It is
helpful to the user to highlight them so that they can be easily recognized. To do this,
create a Highlight annotation as shown in the following example:
this.addAnnot({
page: 2,
strokeColor: color.yellow,
type: "Highlight",
quads: this.getPageNthWordQuads(2, 3),
});
Alerting Users Automatically for Required Form Fields
A user action such as clicking a
Submit
button or leaving a page could trigger validation
scripts detecting either bad input or blank form fields that alert the user to the fact that
some required form fields require their attention.
For example, suppose the user has forgotten to fill in the text field
myText
and has clicked
the
Submit
button. The following script would alert the user to the problem, and could be
followed with code that highlights the text:
app.alert("You forgot the field shown in yellow.");
Making a Form Fillable
In order for a form to be fillable, its text fields or combo boxes must be formatted so that
the user can edit them.
Enabling Typing
If you would like a text area to be enabled for typing, set its
readonly
property to
false
,
as shown in the following code:
f.readonly = false;
If you would like a combo box to be enabled for typing, set its
editable
property to
true
, as shown in the following code:
f.editable = true;
102
Acrobat JavaScript Scripting Guide