By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,568 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,568 IT Pros & Developers. It's quick & easy.

Modifying a onkeyup event to ignore Tab keypress

P: n/a
Is there anyway to tweak this to ignore the function() only if the Tab
key is pressed?
onkeydown="javascript:function();"
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ma******@yahoo.com (Matthew) writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
Lasse Reichstein Nielsen wrote on 08 feb 2004 in comp.lang.javascript:
ma******@yahoo.com (Matthew) writes:
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(); }"


Isn't it this what the OP wants:

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


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #3

P: n/a
> 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?
Jul 20 '05 #4

P: n/a
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?
Jul 20 '05 #5

P: n/a
ma******@yahoo.com (Matthew) writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.