Strange onkeypress event with ESC in Firefox...
Hi all,
I have the following code:
<input onkeydown="return testKey(event)" type="text"/>
function testKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode;
alert(charCode)
}
- This code works perfectly in IE with no errors
- In Firefox (Using FireBug to check for JS errors) the code alerts every character fine except for 1 key which is the ESC key. When i press the ESC key in that input field FireBug throws an error saying: "event is not defined". So for some retarded reason Firefox is looking at the event.keyCode part (which is supposed to be used for IE only) for only the ESC key (all other keys dont throw up an error).
EDIT: Ok i have figured out why its happening now, because Firefox charCode returns 0 and IE returns undefined and when you do 0 || undefined it returns undefined which i didnt think would be the case. Anyone have an idea how to get around the ESC key besides detecting for 0 and undefined?