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

Complete coding newbie needs help: Automatic field advance?

nefm
Registered: Jul 7 2009
Posts: 16
Answered

I am creating Acrobat forms from scanned paper forms used by the PTA at my school. The directory information form has 3 separate areas for the phone number (area code, prefix, and last 4 digits). The form wizard created 3 separate comb fields. I am OK with this if there is some way I can get the input to advance automatically when full instead of the user having to use the tab key or manually click into the next field. I don't especially want to create a single field for the phone number because people who fill out the form with a pen and paper (and there will be some) need to use the 3 separate areas and I don't want to have 2 versions of the same form. Can anyone help?

Thanks in advance.

My Product Information:
Acrobat Pro 9.0, Macintosh
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Yes, and this method has been around since Acrobat version 4. This predates the introduction of the "Comb" field property.The code was originally designed for the entry of numeric values from 1 to the specified field length. It has been expanded to include the ability to accept alphabetic characters through the use of an optional logical value parameter. I first saw this code in an article by Ted Padova.

One needs to set the limit of characters for the field or the size of the comb field, for this code to work.

The following function code is placed as a document level script and the function is then called by each of the comb fields or other field as needed.

// document level function for auto tabbingfunction goNext(oItem, oEvent, cName, bAlpha) {/* 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

bAlpha - optional - logical value to identify an alpha field

 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 and decimal point of '.' for multi character fields. Call for numeric only field:

goNext(this, event,"NextField"); Call for an alpha/numeric value input:goNext(this, event "AlphaNextField", true)*/
try{ // error catcherif (bAlpha) {if (AFMergeChange(oEvent).length == oEvent.target.charLimit) oItem.getField(cName).setFocus();}else {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 fieldapp.beep(3); // beepconsole.println("Error: " + eMsg + "\nField: " + oEvent.target.name + "\nNext Field: " + cName);} finally { // always runreturn; }} //end goNext function

For each field of a fixed length to be tabbed out after the maximum number of characters has been entered, on enters the following code into the "Custom keystroke" section on the "Format" tab for the "Custom" format option:
// custom keystroke codegoNext(this, event, "Next_Field_Name");

One only needs to replace the "Next_Field_Name" with string with the name of field to be tabbed into.

George Kaiser

nefm
Registered: Jul 7 2009
Posts: 16
Thank you so much for your extremely quick reply. I am going to see if I can make it work, and will report back.
nefm
Registered: Jul 7 2009
Posts: 16
gkaiseril, you are a genius. It worked perfectly. I know I have a lot to learn, and I am so grateful there are people like you around to teach me. Thank you.
mtmcardle
Registered: Jul 23 2009
Posts: 14
Sorry- I am completely confused. I have a form I'm making (had Adobe Acrobat Pro 9) that was pulled from a word document and it automatically put text fields everywhere I needed them, it also named them for me.

Now I need to go from line to line automatically without having a user pushing to tab button. I've tried putting these scripts in but it keeps giving me errors like "missing } after function body" I put this: function goNext(oItem, oEvent, cName, bAlpha) { in the JavaScript Funtions... am I missing something? Can you dumb you instructions down so I know exactly what and where needs to be touched and changed so this feature can work?

Thank you so much!

Mark
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Have you copied the entire function?

The last 2 lines are:
Quote:
return; }
} //end goNext function
You need to copy everything from the firs line to the last line.

George Kaiser

mtmcardle
Registered: Jul 23 2009
Posts: 14
Dumb mistake, now it works, but it only lets me key in numbers... any thoughts?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Have you set the 'bAlpha' parameter to 'true', indicating that the field being processed is to be treated as a alphabetic field and not a numeric field.

From the comment describing the function:
Quote:
Call for an alpha/numeric value input:
goNext(this, event "AlphaNextField", true)

George Kaiser

mtmcardle
Registered: Jul 23 2009
Posts: 14
here's what i did:

click advanced > document processing > document javascripts > added a new one called tab and pasted the following:// document level function for auto tabbing
function goNext(oItem, oEvent, cName, bAlpha) {
/* 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
bAlpha - optional - logical value to identify an alpha field
bUpper - optional - logical value to force entry to upper case

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 numeric only field:
goNext(this, event,"NextField");

Call for an alpha/numeric value input
goNext(this, event "AlphaNextField", true)
*/
try{ // error catcher
if (bAlpha) {
if (AFMergeChange(oEvent).length == oEvent.target.charLimit) oItem.getField(cName).setFocus();
}
else {
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
console.println("Error: " + eMsg + "\nField: " + oEvent.target.name + "\nNext Field: " + cName);
} finally { // always run
return; }
} //end goNext function

then saved it... then i went to my text block and clicked properties > format > select format category: custom > edit custom keystroke script: // custom keystroke code
goNext(this, event, "passage 2");


That is all I've done.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You still have [b]not[/b] set the [b]'bAlpha'[/b] parameter to [b]'true'[/b]. If this parameter is omitted, the assumption of the function is the field is a numeric field and treated as a numeric value. When this parameter is omitted the value of the [b]'bAlpha'[/b] parameter has a value of 'unknown' and is not equal to the value of 'true' so the code for processing alpha numeric values is skipped and only the code for the processing of numeric values is used.

To indicate the field with the auto tab being used for should allow the use of alphabetic characters, one needs to include the 4th positional [b]optional[/b] parameter [b]'bAlpha'[/b]. So to process your field that may contain alphabetic characters one needs to code:
goNext(this, event, "passage 2", true);

George Kaiser

mtmcardle
Registered: Jul 23 2009
Posts: 14
Sorry for being so complicated... how do I set the bAlpha to true? Where is that, in the initial document java? or in the individual text box properties?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
It is part of the document level script defining the custom function and the parameters that can be used by the function.

The following function statement names the function, 'goNext', and list the parameters 'oItem', 'oEvent', 'cName', and 'bAlpha'.

Quote:
function goNext(oItem, oEvent, cName, bAlpha) {
In custom defined functions, all the parameters are positional, so the position indicates what parameter is being passed. Optional parameters can be omitted or provided. If there are any parameters beyond an omitted parameter, one needs to indicate the omitted parameter by use of the parameter separator. If the omitted optional parameter is the last parameter nothing has to be entered.

The parameters are positional, meaning the position of the passed value is describes the parameter.
'oItem' - identifies the document object to use - usually the current document and has the value of 'this'.
'oEvent' - identifies the event to be processed - usually the calling event and has the value of 'event'
'cName' - is the field name for the next field to be processed when the field being processed reaches its maximum character count.
'bAlpha' - if present (optional) and with a value of 'true' indicates the field being processed is to be treated as a character string and not as a numeric value.

To process a numeric field one can use:
// optional bAlpha parameter omittedgoNext(this, event, "Number Field 2");

or:
// optional bAlpha parameter set to indicate process as a numeric fieldgoNext(this, event, "Number Field 2", false);

And to process a field that may contain non-numeric values, one has to code:
// optional bAlpha parameter set to indicate non-numeric data is to be processedgoNext(this, event, "passage 2", true);

George Kaiser

mtmcardle
Registered: Jul 23 2009
Posts: 14
Okay, another question, do I have to go individually into every single text box and apply the script or is there a way to select more than one and apply it to many?

Thanks,
Mark
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Only for those fields that are non-numeric do you have to add the 'bAlpha' parameter to the calling of the function by that field's custom keystroke script.

George Kaiser

mtmcardle
Registered: Jul 23 2009
Posts: 14
Awesome I got it to work! one more! Is there an easy way to figure out the max characters for the text block or is there a way to say "once it hits the max space go to next block?"
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
No this script only works for fields that have a set maximum number of characters or a comb field which requries a set character size.

George Kaiser