Recently I was working on a piece of code that would show or hide particular elements based on a Radio option’s ‘checked’ property.
I used the onChange event to fire my code, because that’s what I was doing to the radio option, right?
In a way yes it worked – in every browser but IE. After reading a post about browser inconsistencies I learned that IE doesn’t fire the onChange event, until after I lose focus of the option I just changed – which just doesn’t make sense!
Here’s a quick example of what I’m talking about. Try this in different browsers.
Needless to say, using onClick instead fixed the problem. It seems that onChange still exists for the user who sometimes prefers not to use a mouse when navigating a website. For the purposes of the few, I try to use both events (providing the function to be called checks the status of things to avoid double handling).