Detecting Tab Key Help Needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Freshour

    Detecting Tab Key Help Needed

    I'm trying to use JS to move the cursor from my user login text field
    to the password text field - I've put the onKeyPress() event in the
    user input tag but then I press the Tab key the cursor doesn't move -
    can someone please help me with this? Thanks...

    function detect_tab_key( )
    {
    var key_code = window.event.ke yCode;
    if (key_code == 9)
    {
    document.forms[0].frm_password.f ocus();
    document.forms[0].frm_password.s elect();
    }
    }

  • VK

    #2
    Re: Detecting Tab Key Help Needed

    Tab key is a "system button". It means that you cannot reprogram it, the
    default system behavior will always override your script (the same way the
    F1 key always returns browser help, no matter what action did you attach to
    this).

    Solution are:
    1. Simply place login and password one after another in the form. It will
    give you the same effect without any programming.
    2. If your form layout ABSOLUTELY requires to put some extra stuff between
    these fields, than use TABINDEX property (IE 4.x and higher):

    <input name="field1" ... tabindex="1">
    <input name="field2" ... tabindex="3">
    <input name="field3" ... tabindex="2">

    Being on field1, on tab press the focus will jump on field3 first


    Ralph Freshour <ralph@primemai l.com> wrote in message
    news:04ltkv4sis 420t3or9uaca1ub 789f606cg@4ax.c om...[color=blue]
    > I'm trying to use JS to move the cursor from my user login text field
    > to the password text field - I've put the onKeyPress() event in the
    > user input tag but then I press the Tab key the cursor doesn't move -
    > can someone please help me with this? Thanks...
    >
    > function detect_tab_key( )
    > {
    > var key_code = window.event.ke yCode;
    > if (key_code == 9)
    > {
    > document.forms[0].frm_password.f ocus();
    > document.forms[0].frm_password.s elect();
    > }
    > }
    >[/color]


    Comment

    Working...