JQuery and the Change Event of Checkbox and Radio Button in Internet Explorer

12/1/2009 9:44:41 AM

 I've been using JQuery for most client side updates these days and one thing has always bothered me.  Coding against the change event of a checkbox or radio button in Internet Explorer always waits until you leave the control before firing the event.  This can produce incorrect results, especially if you are attempting to tally the number of selected items in a list of checkboxes.  Very frustrating...

I finally decided to look into the issue and discovered that it is just the way things are with IE.  The code snippet below will force radio buttons to blur and focus again when they are clicked.  This leaving of the control and coming back will cause your event to fire correctly.  Hopefully IE9 will correct this and we won't need a silly workaround anymore.

$(function() {
    if ($.browser.msie) {
        $('input:radio').click(function() {
            this.blur();
            this.focus();
        });
    }
});

 

Tags:jquery
edb02bd5-e33a-44c9-8433-1d69a06d09da

Comments:

12/30/2009 12:26:01 AM
Dan
Great workaround- exactly what I've been struggling with. Thanks!
Name:
Email: (Your email will not be displayed or distributed in any way)
Comment:
  • © brentman.com 2009-2010 | This site licensed under a Creative Commons license
  • The opinions expressed on this site are my own and not those of my employer.
Log In
 
 
login