Using Acrobat JavaScript in Forms
Forms Essentials
6
Creating Multiple Form Fields
The best approach to creating a row, column, or grid of form fields is to use array notation
in combination with hierarchical naming.
For example, the following code creates a column of 3 text fields:
var myColumn = new Array(3);
myColumn[0] = "myFieldCol.name";
myColumn[1] = "myFieldCol.birthday";
myColumn[2] = "myFieldCol.ssn";
var aRect = [36, 36, 72, 144];
for (var i=0; i<myColumn.length; i++)
{
aRect[1] += 100; // move the next field down 100 points
aRect[3] += 100; // move the next field down 100 points
var f = this.addField(myColumn[i], "text", 0, aRect);
Creating Form Fields That Span Multiple Pages
From a programmatic standpoint, duplicating form fields across multiple pages requires
the same steps as duplicating form fields in general (see
Duplicating Form Fields).
The only
difference is specifying the page number.
To duplicate form fields in general, assign the same name and actions to each of them. In
the example below, we will create duplicate text fields, each named
myField
, on every
page of the document, and we will set the background color of every instance to yellow:
for (var p = 0; p < this.numPages; p++)
{
var aRect = [36, 36, 72, 144];
var f = this.addField("myField", "text", p, aRect);
f.fillColor = yellow;
}
Defining the Tabbing Order
You may specify the tabbing order on a given page by invoking the
doc
object’s
setPageTabOrder
method, which requires two parameters: the page number and the
order to be used.
There are three options for tabbing order: you may specify tabbing by rows (
"rows"
),
columns (
"columns"
), or document structure (
"structure"
).
For example, the following code sets up tabbing by rows for page 2 of the document:
this.setPageTabOrder(2, "rows");
Acrobat JavaScript Scripting Guide
105