maheshforum Posted September 11, 2007 Share Posted September 11, 2007 Hi, I need to get the keycode of the keys . I'm using the following code to display the keycode. But every time when i press a key It displays undefined.function getKeycodes(e){ var KeyID = (window.event) ? event.keyCode : e.keyCode; var keyID1=this.getValue(); alert(keyID1.keyCode); }Thanks in Advance,Maheshwaran Devaraj Link to comment Share on other sites More sharing options...
simo Posted September 11, 2007 Share Posted September 11, 2007 take thisfunction getKeycodes(e) { var keycode; if (window.event) keycode = window.event.keyCode; alert("keycode: " + keycode); }<input type=text onkeyup="getKeycodes(this)"> Link to comment Share on other sites More sharing options...
maheshforum Posted September 11, 2007 Author Share Posted September 11, 2007 take thisfunction getKeycodes(e) { var keycode; if (window.event) keycode = window.event.keyCode; alert("keycode: " + keycode); }<input type=text onkeyup="getKeycodes(this)">I want to get the keycode without using html. Then how can i get it uwing only javascript..... I need the help Link to comment Share on other sites More sharing options...
Synook Posted September 11, 2007 Share Posted September 11, 2007 document.onkeyup = function(e) { if (!e) e = window.event; var keycode = e.charCode ? e.charCode : e.keyCode;} keycode is the unicode value of the key pressed, this function will run every time the user releases a key. Link to comment Share on other sites More sharing options...
aspnetguy Posted September 11, 2007 Share Posted September 11, 2007 if you put ids in your html elements you can attach the events with javascript. document.getElementById("elementID").onkeyup = keyHandler;function keyHandler(e) { if (!e) e = window.event; var keycode = e.charCode ? e.charCode : e.keyCode;} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.