These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Acrobat 9 Pro Autotab

rmora
Registered: Oct 13 2010
Posts: 2

Hello everyone,
I have created a form with multiple lines and want to know how I can have it auto tab to the next field as opposed to pressing the tab key often.
I am a total noob at javascript. I did find a script at

Quote:

http://kb2.adobe.com/community/publishing/533/cpsid_53343.php

I did follow it, but only lets me type in one character then it moves on to the other field. I want something like that, but I want it to where it can auto tab to the next field once it reaches the max characters of the field.
I have tried to look around and cant find much. I have found a lot of scripts for adobe cycle but not using that now.
Any help really appreciated.
 
Thank you,
Raymond

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
A better and more flexible technique can be found at JavaScript - setFocus Method for tabbing to next form field. There is a document level script that uses the focused field's maximum characters to determine if the field is full. But the script is limited to numeric input by using the following code:// Call the built-in routine to allow numbers only.
AFNumber_Keystroke(0, 0, 0, 0, "", true);

This code can removed and the field will accept any input or you can write your own keystroke validation code.

George Kaiser

rmora
Registered: Oct 13 2010
Posts: 2
George,
Thank you for your prompt response.
I applied the script on my document and it works. The only thing is that I have to set the limit of characters before it can auto tab to the next field.
I was wondering if there was a way to set the script to auto tab once the max characters have been reached on a particular field. Is it possible to set the script to where, once the max characters have been reached, if it can move the whole word over to the next field as opposed to having half of the word stay in "text1" and other half of the word moving to "text2" field?

Thank you,
Raymond
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You can modify the function to add parameter for the limmit:

function AutoTab(doc, event, cNext, nChar)
{
// Call the built-in routine to allow numbers only or other validation script
// AFNumber_Keystroke(0, 0, 0, 0, "", true);
/*
If we've filled in the field completely, jump to the next one.
if (event.rc && AFMergeChange(event).length == event.target.charLimit)
doc.getField(cNext).setFocus();
*/
// use the passed nChar parameter
if (event.rc && AFMergeChange(event).length == Number(nChar))
doc.getField(cNext).setFocus();
}

George Kaiser

JayF
Registered: Aug 7 2010
Posts: 12
As I understand it, with this script, it's not necessary to enter a character limit in Options for a field. Once the maximum number of characters that the field can hold is reached, whatever that may be, the cursor should then move to the next text field. Is that correct?

I added the script, exactly as you've written it in your 2010-10-14 post, as a Document Javascript. In the individual text fields, I'm using the Custom Keystroke script:

In the first text field:
AutoTab(this, event, "Text1");

In the second text field:
AutoTab(this, event, "Text2");

and so forth

I hope that you can help with why this is not working for me.

Jay

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You do not need to set the character limit through the UI, but you are checking the required length with the "nChar" parameter. You will need to add the required length to the called function.

// use the passed nChar parameter
if (event.rc && AFMergeChange(event).length == Number(nChar))
doc.getField(cNext).setFocus();
}


George Kaiser

alishadesiree
Registered: Apr 4 2011
Posts: 2
@gkaiseril

Okay, here's what I have:

I have created a simple form with several fields. Some text, some check box. There are two seperate areas that I need the autotab function for. In each case I want one text field to tab to the next one. I have set the maximum character length for the first line of each area. No other maximums have been set. I need to be able to enter both alpha and numeric values. How do I get the autotab script to work in this case? Start to finish please. This is my first experience with pdf javascripts.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The simplest is to create 2 document level functions, one to process numbers and one to process alpha numeric values.

For integers:

function AutoTabInt(doc, event, cNext)
{
// Call the built-in routine to allow numbers only.
AFNumber_Keystroke(0, 0, 0, 0, "", true);
// end format testing
// If we've filled in the field completely, jump to the next one.
if (event.rc && AFMergeChange(event).length == event.target.charLimit)
doc.getField(cNext).setFocus();
}

For alphabetic characters of alphabetical characters and numbers with not specific format:

function AutoTabAlpha(doc, event, cNext)
{
// If we've filled in the field completely, jump to the next one.
if (event.rc && AFMergeChange(event).length == event.target.charLimit)
doc.getField(cNext).setFocus();
}

With some additional coding one could combine the two scripts into one and even possibly adding a parameter that would describe the RegExp pattern and flags for the keystroke verification.

George Kaiser

alishadesiree
Registered: Apr 4 2011
Posts: 2
gkaiseril wrote:
You can modify the function to add parameter for the limmit:function AutoTab(doc, event, cNext, nChar)
{
// Call the built-in routine to allow numbers only or other validation script
// AFNumber_Keystroke(0, 0, 0, 0, "", true);
/*
If we've filled in the field completely, jump to the next one.
if (event.rc && AFMergeChange(event).length == event.target.charLimit)
doc.getField(cNext).setFocus();
*/
// use the passed nChar parameter
if (event.rc && AFMergeChange(event).length == Number(nChar))
doc.getField(cNext).setFocus();
}
Keeping in mind that I really have no clue what I'm doing, I've been trying to use this code. I finally figured out how to get --

function AutoTab(doc, event, cNext)
{
// If we've filled in the field completely, jump to the next one.
if (event.rc && AFMergeChange(event).length == event.target.charLimit)
doc.getField(cNext).setFocus();
}

-- to work. (I didn't know to use the custom keystroke script along with the document level script.) So I'm assuming there's more to this code as well. I'm entering it exactly as keyed in the 10/14 post with no substitutions. Is that correct? Also, what keystroke script should I be using?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
If it is single cells, you can use the comb property.

You need to place the function code according to Entering Document Scripts by Thom Parker.For the custom keystroke script you need to enter:

var cNextFieldName = "Name of next field";
AutoTab(this, event, cNextFieldName);

Change the string "Name of next field" to the name of the field you want to jump to. Remember to keep the name of the field between quotation marks.

George Kaiser

digicorn
Registered: Jun 27 2011
Posts: 1
I am brand new to this; I have never written a Java script before and have no concept of how it even works. I read the posts and visited the sites displayed here. The sample file from the second site (http://www.planetpdf.com/developer/article.asp?ContentID=javascript_setfocus_method_f&gid=6267) is exactly what I want to do, but when I copy the format, it doesn't work for me (Acrobat 9.4.5 on OS 10.5.8). I can't figure out what I am doing wrong. I would love to attach a screenshot, but instead I'll post my script:AutoTab(this, event, "Description.1");

I have 5 fields I want to autopopulate with text (Description.0 through Description.4). I set a character limit of 89 characters, and specified a particular font and font size. I tabbed through the sample document and matched all settings, but all that happens for me is it reaches 89 characters and then just stops. I don't want to have to tab each time; I just want the text to flow continuously.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
There is a document level function that performs the heavy lifting of checking to see if the form field is full and then sets the focus to the next field. A programing function similar to mathematics function, is a series of statements that describes a repeated action, and may take one or more parameters and return an expected result or action.

For the referenced Planet PDF article, JavaScript - setFocus Method for tabbing to next form field, has an note annotation:"These three fields "auto-tab" to the next field when they reach their character limit.

"They use the document level script AutoTab that takes three parameters. The first is the current document, the second is the event object, and the third is the name of the field to tab to.

"his sample will only work in Acrobat 4.05 and greater which exposes the setFocus() method for the field object."

The function's code is something like:

function goNext(oItem, oEvent, cName) {
/* Tab to next field when field character limit is reached.
Includes alpha fields and case change.
Includes error trapping and displays on JavaScript console
the error, field where error occurred and next field name.

parameters:
oItem - required - item where fields to process reside
oEvent - required - field being processed
cName - required - next field's name

Place call to this function in the fields custom format.
The user responsible for checking format of field.
Default number check is for the standard numeric values.
"0-9" for single character fields and includes sign values for multi character fields.

Call for number field:
goNext(this, event,"NextField");
*/
try{ // error catcher
AFNumber_Keystroke(0, 0, 0, 0, "",true);
if (oEvent.rc && AFMergeChange(oEvent).length == oEvent.target.charLimit) oItem.getField(cName).setFocus();
} catch(eMsg) { // trap error display error message, field in and next field
app.beep(3); // beep
} finally { // always run
return; }

} //end goNext

See Entering Document Scripts by Thom Parker for instructions on how to enter, access, or edit document level scripts.

George Kaiser