Modifying a onkeyup event to ignore Tab keypress

M

Matthew

Is there anyway to tweak this to ignore the function() only if the Tab
key is pressed?


onkeydown="javascript:function();"
 
L

Lasse Reichstein Nielsen

Is there anyway to tweak this to ignore the function() only if the Tab
key is pressed?
onkeydown="javascript:function();"

"function" is a keyword, so it is a bad example to use.
The "javascript:" is not needed.

onkeydown="if ((event.keyCode||event.which) != 9){ func(); }"

The event.which is meant for Netscape 4, but a little wasted on this
example, since it won't catch the tab key anyway.

/L
 
E

Evertjan.

Lasse Reichstein Nielsen wrote on 08 feb 2004 in comp.lang.javascript:
"function" is a keyword, so it is a bad example to use.
The "javascript:" is not needed.

onkeydown="if ((event.keyCode||event.which) != 9){ func(); }"

Isn't it this what the OP wants:

<input
onkeydown="return (event.keyCode||event.which) != 9;"
 
M

Matthew

Isn't it this what the OP wants:<input onkeydown="return (event.keyCode||event.which) != 9;">

I am confused with this, basically I want whatever(); to execute
somewhere in there... I couldn't get the other posters version to work
and I don't see how to call my function with this. Any ideas?
 
M

Matthew

Ok, slight update here... I stand corrected, the other posters version
works, except when I implement it on a onkeyup instead of onkeydown,
it oddly ignores the call...


onkeyup="if ((event.keyCode||event.which) != 9){ something(); }"
onkeydown="if ((event.keyCode||event.which) != 9){ something(); }"

Separately, what is the keyevent # for a SHIFT-TAB?
 
L

Lasse Reichstein Nielsen

Separately, what is the keyevent # for a SHIFT-TAB?

The keyCode is still 9 (in the browsers I have tested), but the
event's shiftKey property will be true as well. However, just pressing
the shift key alone will trigger the keydown with keyCode 16, which
you might want to avoid too.

onkeydown="if (!(event.keyCode==9 && event.shiftKey)){something();}"

should call something except when you press shift-Tab. Including when
you press shift.

onkeydown="if (!(event.keyCode==16 || (event.keyCode==9 && event.shiftKey)))
{something();}"

This should omit the shift as well.

/L
 

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,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top