Jump to content

Error in Keyup event


maheshforum

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...