A Short Acrobat JavaScript FAQ
How can I hide an Acrobat form field based on the value of another?
A
How can I hide an Acrobat form field based on the value of another?
Use the
display
method of the
Global
object:
var title = this.getField("title");
if (this.getField("showTitle").value == "Off")
title.display = display.hidden;
else
title.display = display.visible;
How can I query an Acrobat form field value in another open form?
One way would be to use the
Global
object's
subscribe
method to make the field(s) of
interest available to others at runtime. For example, a form may contain a document-level
script (invoked when that document is first opened) that defines a global field value of
interest:
function PublishValue( xyzForm_fieldValue_of_interest ) {
global.xyz_value = xyzForm_fieldValue_of_interest;
}
Then, when your document (Document A) wants to access the value of interest from the
other form (Document B), it can subscribe to the variable in question:
global.subscribe("xyz_value", ValueUpdate);
In this case, ValueUpdate refers to a user-defined function that is called automatically
whenever
xyz_value
changes. If you were using
xyz_value
in Document A as part of a
field called
MyField
, you might define the callback function this way:
function ValueUpdate( newValue ) {
this.getField("MyField").value = newValue;}
How can I intercept keystrokes one by one as they occur in Acrobat
forms?
Create a Custom Keystroke Filter script (see the Format tab in the
Properties
dialog for any
text field or combo box ) in which you examine the value of
event.change
. By altering
this value, you can alter the user's input as it takes place.
Acrobat JavaScript Scripting Guide
269