Accessibility
Adobe
Sign in Privacy My Adobe

Community Publishing

Created:
2010-01-04
Last Updated:
2012-01-11
by
User Level:
Intermediate/Advanced
Products:
Acrobat 3D
Acrobat Pro Extended
Acrobat


Need more tips and tutorials?


DEVELOPING AUTOMATIC TAB ORDER

 

 

This tip is for JavaScripts written for Adobe Acrobat.

 

 

 

When it’s necessary to control the number of letters or numbers allowed in a form field, you could design a combo form that contains fields with individual boxes designed to hold a single character representing a field along a row.

Without JavaScript, the user would have to manually tab to each field to make an entry. We’ll learn how to do this with JavaScripts that auto tabs to the next field when a letter is entered.

We’ll begin by using a Document Level JavaScript.

Instructions:

1.       On the Main Tool bar, click  >  Advanced and follow the sequence in Figure 1.

form field access image

This is the only way to access the Document Level JavaScript dialog boxes.

2.       When you click Document JavaScript, you’ll be presented with this dialog box to enter a name for the script and insert the script as shown in Figure 2.

Script dialog box image

3.       Enter this script in the dialog box.

 function nextField() {

 try{

  var fieldName = event.target.name.split(".");

  var counter = fieldName[1];

  var next = fieldName[0] + "." + ++counter;

 var nextField = this.getField(next);

  if (nextField != undefined)

     return nextField;

  else 

     return this.getField(fieldName[0] + "." + 1);

     } 

catch(e) { app.alert(e); }

}

 

This script loops through all individual fields for each set of fields with a common parent name on the form. In this example, firstname.N is used for the first name fields. N is the child value for the fields and use in this example as firstname.1, firstname.2, and so on. If the field contents are not defined (! = undefined), the next field is returned (jumps to the next field). The try/catch statements are used to catch exceptions. 

4. Create a text field for the first field and set the properties as follows:

  • General tab: Name = firstName

  • Appearance tab: Pick a Border Color, Fill Color, and Font size.

  • Options tab: Alignment = Center, Scroll Long Text = checked,  Limit one 1 character, check spelling

  • Format tab:  Select format category = Custom, Custom Keystroke Script =  nextField().setFocus();

5. Duplicate the field by right click the text field and select Place Multiple Fields. You need to determine how many duplicate fields you need and in which direction (vertical or horizontal). See Figure 3. 

duplicate fields image

Note: Each new field will be indexed automatically (example: firstName.1, firstName.2, firstName.3) and the last field has to set focus to the next field category  - example : this.getField('nextFieldName').setFocus();

6.Create the first field in the next group and add the same script for the Format properties. 

A working example of this tip is available from the link titled "Auto Tab Order Demo" . Download it and examine the scripts in the Page Navigation, text fields and Document Level JavaScript. Pay attention to the fact that the form resets when it's re-opened and the default tab order is by Rows. 

Auto Tab Order Demo

 

How to open the Form Tool bar

 1. Use the Main Tool bar. This is also the way to open the Form Tool bar in Acrobat.

form tool bar image

2. Do not click Yes  (Figure 5) unless you have not setup and added any form fields. Clicking No will preserve the form fields you’ve already created.

form field recognition image

3. Use this method when you need to edit fields that have already been saved or used. Each item on a form is called an Object.

field editor image

 


About the contributor 

Eugene Williams is the manager of the Adobe Acrobat User Group in Las Vegas Nevada. This user group holds meetings at the New Horizon Computer Learning Center, 7674 W. Lake Mead Blvd., Suite 250, Las Vegas, NV 89128 and occasonal online meetings at http://acrobat-vegas.groups.adobe.com/.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License