Connecting Tech Pros Worldwide Help | Site Map

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

Scott Eade
Guest
 
Posts: n/a
#1: Jul 23 '05
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
Danny
Guest
 
Posts: n/a
#2: Jul 23 '05

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



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


On Wed, 13 Jul 2005 19:27:01 -0700, Scott Eade <seade@westnet.com.au>
wrote:


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Scott Eade
Guest
 
Posts: n/a
#3: Jul 23 '05

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


Danny wrote:[color=blue]
>
> 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
>[/color]
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
Closed Thread