...

View Full Version : how to detect user click the "numeric" button?



NinjaTurtle
08-20-2002, 05:52 AM
dear,

i'm doing a calculator using Javascript, i want to detect user click on the numeric button from the keyboard. possible?
when user click "1" i will set the "button"(HTML) number 1 was clicked?

x_goose_x
08-20-2002, 02:27 PM
document.onkeydown=checkKeys;
if (navigator.appName == 'Netscape')
document.captureEvents(Event.KEYDOWN);



function checkKeys(e)
{
if (navigator.appName == 'Netscape')
theKey = e.which;
else
theKey = window.event.keyCode;
if ((thekey>=48&&theKey<=57)&&(thekey>=96&&theKey<=105)) {
key = String.fromCharCode(theKey);
alert("You Pressed: "+key)
}else{
alert("This is not a number");
}
}


You''ll need to play around with it a bit. Right now it filters out the numbers, but if you want them to be able to press * / - + = you'll need to add them in. You can also have them enter the text in a textbox, it would be much easier.

NinjaTurtle
08-23-2002, 03:16 AM
this only work on Netscape? how about IE?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum