One of most common event related questions I got is about error in Mozilla browsers “event is not defined”.
IE and Mozilla treat event variable differently, while in IE it is a global variable (accessible without passing it to the function) in Mozilla you need to pass it every time (which btw is by w3c standards).
Example 1:
this would work in IE, but NOT in Mozilla
element.onkeypress = function() {
return isNumberInput(this, event);
};
Example 2:
this works in IE AND Mozilla
notice that event variable is passed to the function
element.onkeypress = function(event) {
return isNumberInput(this, event);
};
June 12th, 2008 at 4:37 pm
Thanks for such a simple answer!
July 29th, 2008 at 7:23 am
Thank you! You just helped me solve what turned out to be a simple problem.