Using Acrobat JavaScript in Forms
Forms Essentials
6
Combo Box Properties
The combo box has the same properties as the button and check box fields. Its primary
differences lie in its nature. Since the combo box maintains an item list in which the user
may be allowed to enter custom text, it offers several properties that support its formatting
options.
If you would like the user to be permitted to enter custom text, set the field’s
editable
property, as shown in the following code:
f.editable = true;
You may decide whether the user’s custom text will be checked for spelling by setting its
doNotSpellCheck
property. The following code indicates that the spelling is not
checked:
f.doNotSpellCheck = true;
A combo box may interact with the user in one of two ways: either a selection automatically
results in a response, or the user first makes their selection and then takes a subsequent
action, such as clicking a
Submit
button.
In the first case, as soon as the user clicks on an item in the combo box, an action may
automatically be triggered. If you would like to design your combo box this way, then set its
commitOnSelChange
property to
true
. Otherwise, set the value to
false
. The
following code commits the selected value immediately:
f.commitOnSelChange = true;
To set the export values for the combo box items, invoke its
setItems
method, which can
be used to set both the user and export values. In this case, the user value (the value that
appears in the combo box) is the first value in every pair, and the export value is the second.
The following code results in the full state names appearing in the combo box, with
abbreviated state names as their corresponding export values:
f.setItems( ["Ohio", "OH"], ["Oregon", "OR"], ["Arizona", "AZ"] );
In many cases, it is desirable to maintain a sorted collection of values in a combo box. In
order to do this, you will need to write your own sorting script. Recall that the JavaScript
Array
object has a
sort
method that takes an optional argument which may be a
comparison function.
This means that you must first define a
compare
function that accepts two parameters.
The function must return a negative value when the first parameter is less than the second,
0
if the two parameters are equivalent, and a positive value if the first parameter is greater.
Acrobat JavaScript Scripting Guide
97