Sunday, August 8, 2010

Get event keycode in both Firefox and Internet Explorer

This solution should work in both IE and Firefox.

JS -

function getCharCode(event)
{
var charCode = (event.which) ? event.which : event.keyCode;

// Might want to get the character representation of the Unicode keycode -

var character = String.fromCharCode(keycode);


}

HTML -

Just put an onkeypress="getCharCode(event)" event handeler in your input code (textarea, whatever)