kewley
10-12-2006, 12:31 AM
I am trying to figure out how to display an alert box when the user presses the "h" key? Can anybody help me out?
|
||||
Onkeypresskewley 10-12-2006, 12:31 AM I am trying to figure out how to display an alert box when the user presses the "h" key? Can anybody help me out? warhammerdude20 10-12-2006, 01:07 AM Sure thing... I dont know what your trying to do but id use onKeyDown instead of onKeyPress, but its your call. ok in the body tag you go like this <body onKeyPress="if(window.event.keyCode==72)alert('you pressed H');" > I dont know how good you are with javascript but the keyCode for "H" is 72 hope that helps Philip M 10-12-2006, 08:10 AM Sure thing... I dont know what your trying to do but id use onKeyDown instead of onKeyPress, but its your call. ok in the body tag you go like this <body onKeyPress="if(window.event.keyCode==72)alert('you pressed H');" > I dont know how good you are with javascript but the keyCode for "H" is 72 hope that helps ASCII keyCode 72 is H upper case. Lower case h is keyCode 104. So: <body onKeyPress="if (window.event.keyCode == 72 || window.event.keyCode == 104) alert ('You pressed h or H');" > liorean 10-12-2006, 02:12 PM If you want it to work in other browsers than Internet Explorer: <body onkeypress="var k=event.keyCode||event.charCode||event.which;if(k==72||k==104)alert('you pressed H or h');return false;"> |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum