views:

1196

answers:

1

I tired to write a function to check key code with javascript. It's working fine for firefox but not IE. Does anyone know what is going wrong with my code? Please see below code for more details.

function textCheck(e)
{
 var e = window.event || e
 alert("CharCode value: "+e.charCode)
 alert("Character: "+String.fromCharCode(e.charCode))
}
+2  A: 

switch your first line of code:

...

var e = e || window.event;

...

and see if that helps.

Also, if it is a unicode character try something like the following:

function displayunicode(e) {
    var unicode=e.keyCode? e.keyCode : e.charCode
    alert(unicode)
}

If you're handling keydown instead of keypress, then things get a bit more complex... See: http://unixpapa.com/js/key.html

Adam Markowitz