6
Using Acrobat JavaScript in Forms
Forms Essentials
For example, suppose you would like to place a Button named
myButton
on the first page
of the document. Assume that the button is one inch wide, one inch tall, and located 100
points in from the left side of the page and 400 points up from the bottom of the page
(there are 72 points in 1 inch). The code for creating this button would appear as follows:
var
var
var
var
var
name = "myButton";
type = "button";
page = 0;
location = [100, 472, 172, 400];
myField = this.addField(name, type, page, location);
This approach to creating form fields is applicable to all fields, but it should be noted that
radio buttons require special treatment. Since a set of radio buttons represents a set of
mutually exclusive choices, they belong to the same group. Because of this, the names of all
radio buttons in the same group must be identical. In addition, the export values of the set
of radio buttons must be set with a single statement, in which an array of values are
assigned through a call to the radio button collection’s
setExportValues
method.
For example, suppose we would like to create a set of three radio buttons, each 12 points
wide and 12 points high, all named
myRadio
. We will place them on page 5 of the
document, and their export values will be
"Yes"
,
"No"
, and
"Cancel"
. They can be
created as shown in the code given below:
var name = "myRadio";
var type = "radiobutton";
var page = 5;
this.addField(name, type, page, [400, 442, 412, 430]);
this.addField(name, type, page, [400, 427, 412, 415]);
var rb = this.addField(name, type, page, [400, 412, 412, 400]);
rb.setExportValues(["Yes", "No", "Cancel"]);
This code actually creates an array of 3 radio buttons, named
myRadio.0
,
myRadio.1
,
and
myRadio.2
.
90
Acrobat JavaScript Scripting Guide