cat brain.log | less

Getting it down on `paper`

jQuery and Radio Inputs on Internet Explorer: Use Caution

Today’s entry comes from that fantastically obtuse world of Internet Exploder. The lesson today is: wrap your onchange functions in a container function.

The problem: Radio input change events in Internet Explorer are not sufficiently executed when triggered using the jQuery.change method, passing in a named function reference as a parameter. The clicked radio button does not remain selected after the event is fired. No radio buttons are selected after the change method is called, even though the function reference is subsequently executed.

The players:
Windows 7, Internet Explorer 8, jQuery 1.4.2, 1.4.3, and/or 1.4.4.

jQuery('input[name="radioSet"]').change(function() { updateDisplay(); });

Doesn’t Work:

That input referenced above is supposed to be a collection of radio buttons. In html, it would look like:

<label><input type="radio" name="radioSet" value="42" /> The Answer</label>
<label><input type="radio" name="radioSet" value="?" /> The Question</label>

The updateDisplay is a function defined elsewhere that tries to read the value of the radio group.  It’s defined something like this:

function updateDisplay() {
  var value = jQuery('input[name="radioSet"]').val();
  if( value == "?" ) {
    alert("What is the meaning of life, the universe, and everything?");
  } else {
    alert("Don't forget your towel.");

The bewildered developer asks no further questions. There is no good reason for using Internet Explorer. The IE developers eat kittens. This is just another demonic prank of theirs. I hope you haven’t wasted too much time trying to figure this out.



No comments so far.

(comments are closed)