1 HOME


© 2013 Adobe Systems, Inc. All rights reserved.

Updated Aug 22, 2014.

2   JavaScript APIs and Forms

For Reader Mobile, JavaScript support includes performing built-in forms calculations, data validation, and data formatting using APIs that are a subset of those supported by the desktop product. The JavaScript framework is general enough to support additional JavaScript in the future as it regularly evolves. For the latest details, refer to the API Reference for your platform:

Note

Reader Mobile supports the Acroforms interactive form format authored with Acrobat Pro. It does not support the XFA interactive forms format created with LiveCycle Designer.

2.1   Adding JS via Acrobat

JavaScript in forms allows you to create custom and automatic behaviors that simplify the end user experience, improve the integrity of form data, and perform other actions. Most form authors will find that using JavaScript is relatively simple and accessible.

The following provides some general instructions for adding JS to PDF forms in Acrobat.

  1. Open Acrobat and do either:

    • Open an existing form and choose Tools > Edit.
    • Choose Tools > Create and create a form from an existing file.

Note

You need to be in edit mode to continue.

  1. Add a new form element from the top bar or select an existing element.
_images/formsbar.png
  1. Right click on a form element.
  2. Choose Properties.
_images/formscontextmenu.png
  1. Choose the Actions tab.
_images/formsactionstab.png
  1. Select a trigger that will execute the JavaScript. The most common trigger is Mouse Up, since that means the user has clicked the UI item.
  2. Select Run a JavaScript as the action.
  3. Choose Add.
_images/formselectaction.png
  1. Enter the JavaScript. If your JavaScript is going to perform some action on another field, you’ll need to know the name of that field. In this example, the value of
_images/editjs.png
  1. Choose OK and close the forms dialog.

2.2   Tips and tricks

2.2.1   Use intuitive names

To simplify and speed coding, it’s always a good idea to give you fields intuitive names. Set the name of the form fields on the General tab.

_images/formfieldname.png

2.2.2   Interacting with multiple fields

There are several options for working with multiple fields.

Provide a comma-separated list of field names:

this.getField("Textfield1, Textfield2").value = "AAA";

Repeat the JavaScript for each field. In this example, the text in form fields 1 through 4 changes from its current value to AAA, BBB, CCC, and DDD:

this.getField("Text1").value = "AAA";
this.getField("Text2").value = "BBB";
this.getField("Text3").value = "CCC";
this.getField("Text4").value = "DDD";

Loop through an array of field names:

var fields = new Array();
fields[0] = "Text1";
fields[1] = "Text2";
fields[2] = "Text3";
this.resetForm(fields);

2.2.3   Form submission

In Acrobat, there are two ways to set up forms submission: via the Submit a Form Action or by running a Javascript. The former provides additional URL options (e.g. mailto) as well as additional format and export settings. The JavaScript method only supports HTML submission to FormsCentral. Charset must be set to utf-8.

this.submitForm(
  { cURL:https://adobeformscentral.com/?f=yeaCGAwDe8%2A-fsUVqbmdTg,
    cSubmitAs:HTML,
    cCharset:utf-8 } );
_images/submittwoways.png _images/submitaform.png