kewley Posted October 11, 2006 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? Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 12, 2006 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 Link to comment Share on other sites More sharing options...
kewley Posted October 12, 2006 Author Share Posted October 12, 2006 Thanks a lot!! Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 12, 2006 Share Posted October 12, 2006 Sorry for the quick post. I was in a rush.Glad I could help. :)Choco Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now