I am trying to get the code of an event using the event.which jQuery function. It is working great in FF, but in IE8 I am only getting “undefined”. Is there some reason this would not work in IE8? I am using jQuery version 1.3.2 and the code is bellow (simplified).
function handleInput(event) {
//Get the character code of the pressed button
keycode = event.which;
}
Thanks,
Metropolis
** EDITED **
Basically what I want to be able to do is have an HTML element with an onkeyup event attribute which will call to the handleInput function. Here is what I want the HTML to look like.
<input type="text" value="" onkeyup="handleInput(event)" />
Is there a way to pass “event” like this and have jQuery recognize it?
jQuery does support
event.which. How exactly are you binding your handler? Are you using jQuery? If you’re doing:It should work. You probably don’t want to use
event(notice that I am passing inevtversusevent) as the parameter since it will collide with IE’s event object. I believe this is the source of your problem.EDIT
After reading your comment, you need to do something like this in a Javascript file that you reference from
<HEAD>: