Tab jumping to address bar, not next field after select() [IE]

Discussion in 'Javascript' started by Scott Eade, Jul 14, 2005.

  1. Scott Eade

    Scott Eade Guest

    I am using select()/focus() to position the cursor at a particular field
    on a form. This works, but when the user presses the Tab key in IE the
    cursor jumps to the address bar rather than the next field (Firefox is
    fine). Does anyone know why this might be happening and how to stop it?

    Below is the code that I use to set the cursor position (it is somewhat
    convoluted because it is generated via a series of macros). The cursor
    is positioned correctly, but when I hit Tab the cursor does not follow
    the expected flow through the page (i.e. it doesn't go to the next field).

    // The page contains:
    <script language="JavaScript1.2" type="text/javascript">
    <!--
    var focusId = 'fnameId';
    SafeAddOnload(setFocus);
    //-->
    </script>
    <input id="fnameId" type="text" size="50" name="fname" value="" />

    // From a .js file loaded by the page:
    // SafeAddOnload (used above) just delays execution until the
    // page has loaded.
    // getRef (used below) simply retrieves the DOM object using the id.
    //
    function setFocus()
    {
    obj = getRef(focusId);
    if (obj != null)
    try
    {
    obj.select();
    }
    catch (e)
    {
    obj.focus();
    }
    }

    Thanks in advance for any assistance.

    Scott
    Scott Eade, Jul 14, 2005
    #1
    1. Advertising

  2. Scott Eade

    Scott Eade Guest

    Re: Tab jumping to address bar, not next field after select() [IE]- solved

    Danny wrote:
    >
    > Set a tabindex= on your inputs or just 1 input or so, to the
    > tabpress gets trapped and passed to the tabindex pool, plain html:
    >
    > <input tabindex="1"> <input tabindex="2">
    > when the user presses the tab, it'll use 1 and 2 indexed elements
    > for jumping, leaving out the address box.
    >
    >
    > Danny
    >

    Thanks for the suggestion Danny. I had tried using tabindex and it
    still misbehaved.

    I have just spent a couple more hours on this and have isoated it down
    to the setFocus() implementation - specifically to the exception
    handling. The following replacement code makes it work:

    function setFocus()
    {
    var obj = getRef(focusId);
    if (obj != null) {
    obj.focus();
    if (obj.select)
    obj.select();
    }
    }

    Looks like the exception handling in IE is a little screwed up.

    Scott
    Scott Eade, Jul 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    0
    Views:
    3,538
  2. John Hann
    Replies:
    0
    Views:
    6,066
    John Hann
    Aug 21, 2004
  3. Koos
    Replies:
    16
    Views:
    4,469
    Mitja
    May 8, 2004
  4. jalkadir
    Replies:
    3
    Views:
    426
    jalkadir
    Oct 5, 2005
  5. Steve Lefevre

    noob - jumping to next select box

    Steve Lefevre, Sep 18, 2004, in forum: Javascript
    Replies:
    6
    Views:
    113
    Steve Lefevre
    Sep 19, 2004
Loading...

Share This Page