Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript Capture 10 Keys

Status
Not open for further replies.

skosterow

Technical User
Feb 23, 2002
135
US
Hey guys/Gals,

Need to capture the 10 key, when NUM LOCK is OFF:

here is what i have:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

<!-- Begin
var key = new Array(); // Define key launcher pages here
key['1'] = &quot;/drs/inq.pl&quot;;

key['8'] = &quot;/drs/insurance-information.pl?INSURANCE=INS::CODE01&quot;;
key['9'] = &quot;/drs/insurance-information.pl?INSURANCE=INS::CODE02&quot;;

function getKey(keyStroke) {
isNetscape=(document.layers);
// Cross-browser key capture routine couresty
// of Randy Bennett (rbennett@thezone.net)
eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
which = String.fromCharCode(eventChooser).toLowerCase();
for (var i in key) if (which == i) window.location = key;
}
document.onkeypress = getKey;
// End -->
</script>

This works great with the numbers on the top row of the keyboard..... but i need to capture the 10 key pad when the num lock key is off. Any ideas?

- Scott
 
alert(event.keyCode) - what value does it return when numlock is off?

Test for that as well as the usual keycode.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
Nothing no return, when i hit a key on the numberpad...
 
Try this:
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd&quot;>[/URL]
<html>
<head>
<title>test bed</title>
<script language=&quot;JavaScript&quot;>
function checkKeycode(e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	alert(&quot;keycode: [&quot; + keycode + &quot;]&quot;);
}
</script>
</head>
<body>
<p>Type in here:
<input type=&quot;text&quot; size=&quot;10&quot; value=&quot;&quot; onKeyPress=&quot;checkKeycode(event)&quot;>
</p>
</body>
</html>

with numlock OFF, firebird gives me a keycode of 0 for any number pad key, while IE doesn't even fire the event (useful sometimes).

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top