Tuesday, January 1, 2008

Happy New Year and IE Fun

One of my 2008 resolutions is to restart my blog and focus it on software development. Mostly Coldfusion, javascript, AJAX and general web development.

To kick off the new year, I'll discuss something I learned about IE today that was making my life miserable. Actually, it's something IE did right and everyone else does wrong.

I had some javascript that would check a radio button or check box and enable (or disable) an "Other (Specify)" box on a survey. Being the smart guy I am, I figure I can use the onChange() function since I only care when the field has changed value. Works great in all the browsers I tested except IE. It turns out that IE has a slightly different implementation of onChange(). To make a long story short, in IE, onChange() doesn't fire until an INPUT element loses focus and has changed it's value. This means that the element firing the event is the old radio button or checkbox, not the new one that was just clicked! This is actually the correct behavior (as far as I can tell) and the other browsers have it wrong. My problem was easily corrected by using onClick() .

No comments: