kewley 0 Posted October 11, 2006 Report Share Posted October 11, 2006 I am trying to figure out how to display an alert box when the user presses the "h" key? Can anybody help me out? Quote Link to post Share on other sites
Chocolate570 45 Posted October 12, 2006 Report Share Posted October 12, 2006 function doSomething(e) { var code; if (!e) var e = window.event; if (e.keyCode) code = e.keyCode; else if (e.which) code = e.which; var character = String.fromCharCode(code); if(character.toLowerCase()=="h") { alert("your message here") }} Your body tag:<body onkeypress="doSomething(event)">Adapted from quirksmode.Choco Quote Link to post Share on other sites
kewley 0 Posted October 12, 2006 Author Report Share Posted October 12, 2006 Thanks a lot!! Quote Link to post Share on other sites
Chocolate570 45 Posted October 12, 2006 Report Share Posted October 12, 2006 Sorry for the quick post. I was in a rush.Glad I could help. :)Choco Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.