
Using Help
|
Contents
|
Index
Back
165
Adobe Acrobat Help
PDF Forms
Using Help
|
Contents
|
Index
Back
165
2
Click the Format tab, choose Date, and choose the short month, day, and long year
format option (for example, Feb 2, 2001). Make sure the field is read-only because it will be
a calculated field, and click OK.
3
To create a document level script that is executed each time the document is opened,
choose Tools > JavaScript > Document JavaScripts. Name the script
Today
, and click Add.
4
Delete the automatically generated text that is displayed in the script window, type in
the following text in the exact format, and click OK.
var f = this.getField(“Today”);
f.value = util.printd(“mm/dd/yyyy”, new Date());
This script binds the
Today
field to the variable f, and then calculates the value. The
new
Date()
expression creates a new date object initialized to the current date and time. The
utility object is used to format the date into the month/day/year format.
5
Click OK in the JavaScript Edit dialog box, and then click Close in the JavaScript
Functions dialog box.
Subtracting and dividing two values
You can use JavaScript to automatically calculate the difference between the values in two
fields and display the results. In the following example, you create three form fields in
which the value in the second field is subtracted from the value in the first. The results are
calculated, and the value is automatically displayed in the third field.
You can use this same JavaScript to divide two values by simply substituting a division
sign
(/) for the minus sign (-) in the last line of the script.
To create an automatic calculation of fields:
1
Select the form tool
, and create a text field. For more information, see
“Creating
form fields” on page 145
. Name this field
ValueA
with no spaces.
2
Click the Format tab, choose Number, and choose the number of decimal places, a
currency symbol if needed, and a separator style.
3
Click the Options tab, specify a default value (for example, 1), and click OK.
4
Create a second text field, and name this field
ValueB
with no spaces.
5
Click the Format tab, and make the format of this field the same as for the previous field.
6
Click the Options tab, specify a default value (for example, 1), and click OK.
7
Create a third text field, and name this field
ResultsC
with no spaces.
8
Click the Format tab, and make the format of this field the same as for the previous field.
9
Click the Calculate tab, choose Custom Calculation Script, and then click Edit.
10
In the script window, type in the following text exactly as shown:
var f = this.getField(“ValueA”);
var g = this.getField(“ValueB”);
event.value = f.value - g.value;
11
Click OK.