Javascript onChange arrow keys

teynon picture teynon · Jul 5, 2011 · Viewed 7.6k times · Source

Ok, so we all know that onChange is used to execute javascript code on a select statement when the option changes. However, if you change a select statement using the arrow keys, the onChange event is not called. Is there a way around this? Please help! I'm OCD I know.

--EDIT 1--

Just tested this in IE and arrow keys do work. Apparently it's just Chrome. ** Goes to check firefox

-- Edit 2 --

Tested in Firefox and realized just before an answer below talked about the onBlur action being required for the change. So the answer here is:

Internet Explorer recognizes onChange events from the keyboard as well as clicking on them. Firefox and Chrome both require key events to be followed by blur event in order to call onChange.

Now normally, I don't like Internet Explorer, because it's a piece of garbage... But I think I... unfortunately, have to say they got that one right.

My understanding as to the reasoning for the blur event on chrome and firefox is to save resources, but I disagree with that. I feel it should follow the literal interpretation of the command onChange... Sigh... I suppose I'm probably wrong somehow, though.

Answer

MuthuKumaran picture MuthuKumaran · Jul 5, 2011

I would suggest you to write the required code in Key Up event to capture the Key press and and also check for Key Code. Hope this helps