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

S

Scott Eade

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
 
S

Scott Eade

Danny said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top