Beau,

I'm starting to think Opera has a bug that prevents you from disabling
the default action of the tab key. I found the following excerpt in an
Opera-related forum called Dev Opera which seems to agree with my
experience.

Thanks,
Mike

$$$$Start of Dev Opera Forum Paste
JS: No (standard) way to disable TAB key?
So I've been writing a very simple auto-complete script for one of my
sites that will accept the highlighted entry whenever the user presses
ENTER or TAB. This works perfectly, and thanks to
event.preventDefault() and event.stopPropagation(), I am able to block
the <form> from being submitted when the user presses ENTER. However,
while my script does successfully select the entry from the auto-
complete list, it still tabs into the next field when I press TAB in
Opera (i.e. the element loses its focus). That obviously isn't the
desired behavior, and is quite possibly an Opera bug. (Other browsers
that support preventDefault() and stopPropagation() keep the focus on
the active element in this case.) For those of you who just need to
see this "bug," here's some code (an oversimplified example):
<html>
<head>
<script type="text/javascript">
function cancel(evt)
{
    evt = ( evt || window.event );
    key = ( evt.keyCode || evt.charCode || evt.which || 0 );
    if ( key == 3 || key == 9 || key == 13 )
    {
        evt.preventDefault();
        evt.stopPropagation();
    }
}
window.onload = function()
{
    document.getElementById('a').addEventListener('keypress', cancel,
false);
}
</script>
</head>
<body>
<form>
  <input type="text" id="a" />
  <input type="text" id="b" />
</form>
</body>
</html>
Notice that it does handle ENTER correctly, but not TAB. I do realize
I could use a combination of window.setTimeout() and focus() to regain
the lost focus, but that just seems really sloppy. Any thoughts?

$$$$End of Dev Opera Forum Paste




On May 8, 3:30 pm, Beau Hartshorne <[EMAIL PROTECTED]> wrote:
> On 8-May-07, at 3:15 PM, MikeC wrote:
>
> > Your suggestion produced the following results.
>
> > - Firefox and IE 6.0 - all key presses seem to be DISabled
> > -Opera 9.2 - all key presses seem to be ENabled
>
> > So you seem to have discovered the secret for handling two of my three
> > browsers. But how do I disable the tab key in Opera 9.2?
>
> > This is interesting because my boss who is also our system architect
> > suggested to use Mochikit because a major design point is that you
> > don't really have to struggle very much with differences among the
> > many available browsers. But I can see that although this is a goal in
> > Mochikit, I can also see that it must be a constant uphill battle to
> > achieve this.
>
> In general, use 'onkeypress' handlers for keys that generate visible  
> characters, and 'onkeydown' handlers for  invisible characters.
>
> I don't know why Opera won't let you disable the tab key. It'll take  
> some trial and error to figure it out. (Have you tried listening on  
> window or document instead of on the form field? Have you tried doing  
> something like <input type="text" onkeydown="return false;" />?)  
> Please let us know what you discover.
>
> Thanks,
> Beau


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to