Adobe 12001196 Scripting Guide - Page 55

Using Acrobat JavaScript in Forms, Creating simple JavaScripts, Creating an automatic date field

Page 55 highlights

4 Using Acrobat JavaScript in Forms Creating simple JavaScripts There are a number of simple JavaScripts you can integrate into your forms to enhance their interactive capabilities. The scripts described here are commonly used with Acrobat forms. Trying out these scripts in the forms you create will give you a glimpse of what JavaScript offers. Careful selection of field names when creating forms is an important factor in data collection. If two fields share the same name, they also share the same value. You can use this capability to create fields that have different appearances (that is, appear on different pages and have different background colors) but have the same value. This means you can modify one field and the other field is updated automatically. NOTE: In order to create and use JavaScript in Acrobat, you must have JavaScript enabled. Make sure that JavaScript is enabled by choosing Edit > Preferences > General and selecting JavaScript from the list on the left. Select Enable Acrobat JavaScript if it is not already selected, and click OK. Creating an automatic date field Many forms require a date for tracking purposes. The following procedure shows you how to create a text field that automatically displays the current date when the document is opened. The script you create to display the current date when the document is opened is a document level script. To create an automatic date field: 1. Select the form tool , and create a text field. (For more information, see the section on Creating Form Fields in the Acrobat online help.) Select the General tab and name the field Today. 2. Select the Format tab, choose Date for the format category, and choose a month, day, and year format option (for example, "mmm d, yyyy"). On the General tab, make sure the field is read-only because it will be a calculated field, and click Close. 3. To create a document level script that is executed each time the document is opened, choose Advanced > JavaScript > Document JavaScripts. Name the script Today, and click Add. Acrobat JavaScript Scripting Guide 55

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90

Acrobat JavaScript Scripting Guide
55
4
Using Acrobat JavaScript in Forms
Creating simple JavaScripts
There are a number of simple JavaScripts you can integrate into your forms to enhance
their interactive capabilities. The scripts described here are commonly used with Acrobat
forms. Trying out these scripts in the forms you create will give you a glimpse of what
JavaScript offers.
Careful selection of field names when creating forms is an important factor in data
collection. If two fields share the same name, they also share the same value. You can use
this capability to create fields that have different appearances (that is, appear on different
pages and have different background colors) but have the same value. This means you can
modify one field and the other field is updated automatically.
N
OTE
:
In order to create and use JavaScript in Acrobat, you must have JavaScript enabled.
Make sure that JavaScript is enabled by choosing
Edit > Preferences > General
and
selecting
JavaScript
from the list on the left. Select
Enable Acrobat JavaScript
if it
is not already selected, and click
OK
.
Creating an automatic date field
Many forms require a date for tracking purposes. The following procedure shows you how
to create a text field that automatically displays the current date when the document is
opened.
The script you create to display the current date when the document is opened is a
document level script.
To create an automatic date field:
1.
Select the form tool , and create a text field. (For more information, see the section on
Creating Form Fields in the Acrobat online help.) Select the
General
tab and name the
field
Today
.
2.
Select the
Format
tab, choose
Date
for the format category, and choose a month, day,
and year format option (for example, “
mmm d, yyyy
”). On the
General
tab, make sure
the field is read-only because it will be a calculated field, and click
Close
.
3.
To create a document level script that is executed each time the document is opened,
choose
Advanced > JavaScript > Document JavaScripts
. Name the script
Today
, and
click
Add
.