Skip to main content
Inspiring
February 5, 2011
Answered

Auto tab to next form field

  • February 5, 2011
  • 2 replies
  • 46418 views

In some forms, when the user types in, for example, the area code for   their phone number, they are automatically tabbed to the cell for the 3   digit prefix and upon completing the prefix they are automatically tabbed to the final cell for the phone number. I know that the user can  hit the tab key themselves, but is Acrobat capable of  automatically  doing this using form fields created in Acrobat in version 9 or 10 Pro?

    Correct answer George_Johnson

    It should be the actual name of the next field. The problem with that particular script is for a text field with a three character limit, you have to attempt to enter another character before it will set the focus to the next field.

    Here's a function you can create in a document-level JavaScript that you can call in a text field's custom Keystroke JavaScript that should behave as you want:

    // Document-level function

    function tab_next(next_field_name) {

        // Move to next field if Enter key is pressed
        // or the user has clicked outside of the field
        // or if the number of character is the character limit
        if (event.willCommit || AFMergeChange(event).length === event.target.charLimit) {
            getField(next_field_name).setFocus();
        }
    }

    Then call it like this as the Keystroke script of a text field:

    // Autotab to the "text2" field

    tab_next("text2");

    This particular script will only work if you're set the character limit for the field from which it is called. There are a lot of autotab scripts that folks have created for use with Acrobat (some better than others) that address a particular circumstance, so you'll probably run across more with a search.

    2 replies

    kandices70514105
    Known Participant
    May 1, 2020

    I am still somewhat new to javascripting.  Where does the document level Javascritpt go.  I've done most of my learning on the form field by trial and error.  This may help me tremendously.

     

    KS

    Inspiring
    February 5, 2011

    Sure, see the first example here: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.609.html

    Inspiring
    February 6, 2011

    George,

    Thanks for your reply. This looks promising.

    I set up 3 text fields. The first two have a limit of 3 characters and the third one a limit of 4 characters.

    I copied the JavaScript and put it in the Action for each of the three fields:

    if ( event.fieldFull || event.willCommit ) 

    this.getField("NextTabField").setFocus();


    I'm not sure if I'm supposed to change "NextTabField" to the actual name of the next field or leave it as is,
    so I tried it both ways. In either case, it's not working for me. After typing 3 characters into the first field,
    I have to manually hit Tab to go to the next field. The same for the other two fields.

    Any ideas about what I'm doing wrong?
    Inspiring
    February 6, 2011

    George,

    A couple of months ago you provided a script on Acrobat Users that has to do with tabbing. It's one that would be useful for me, but I've not been able to make it work. I hope you can help.

    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.

    http://acrobatusers.com/forum/forms-acrobat/acrobat-9-pro-autotab

    The script is as follows:

    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();
    }

    In the individual text fields, I'm using the Custom Keystroke script:

    // Autotab to the "Text2" field
    tab_next("Text2");


    I didn't post that script, George Kaiser did. And it doesn't do what you said it does.