Issue with jQuery setting checkboxes as checked in IE6 (not showing as checked?)

The Code:

var lstInstanceIds = getData.lstInstanceIds.split(',');
    for(var i=0; i<lstInstanceIds.length; i++) {
        var value = lstInstanceIds[i];
        $('input[value=' + value + ']').attr('checked','checked');
    }

So all i'm doing is looping a list and setting the attribute checked as checked where the values meet.

This works fine in Chrome, Firefox, IE7/8, Safari. But not in IE6...

Answers


Use attr('checked', true) instead.


IETester is not an accurate representation of a true IE6 environment. Mainly due to using the javascript engine that is in the local machine rather than the IE6 one. I have come across many pages that work and look great in IE6 using IETester but fail horribly when brought up on a real IE6 on Windows XP environment. My suggestion there is to get the free Virtual PC image of IE6 on WinXP SP3. It is very useful in finding real errors using jQuery (though it is still a pain to debug).


I was able to setup a basic example based solely on what you mentioned here (so hopefully I'm not too far off), and it worked testing in IETester with a 6 instance.

<input type="checkbox" id="chk1" value="chk1" />
<input type="checkbox" id="chk2" value="chk2" />
<input type="checkbox" id="chk3" value="chk3" />
<input type="checkbox" id="chk4" value="chk4" />
<input type="checkbox" id="chk5" value="chk5" />

var ids = "chk1,chk3,chk5";
var lstInstanceIds = ids.split(',');
for (var i=0; i<lstInstanceIds.length; i++) {
    var value = lstInstanceIds[i];
    $('input[value=' + value + ']').attr('checked','checked');
}

I've had a similar problem before. To fix it, I used code similar to this:

var lstInstanceIds = getData.lstInstanceIds.split(',');
for(var i=0; i<lstInstanceIds.length; i++) {
    var value = lstInstanceIds[i];
    var checkbox = $('input[value=' + value + ']').get(0);
    if(checkbox.checked == false)
        checkbox.click();
}

This checks whether the checkbox is checked. If not, it clicks it, thereby checking it. Should support all browsers!


Need Your Help

Changing X & Y of Button upon Rotation

iphone rotation xamarin.ios

Edited Mar 30 - Note: Monotouch used. When I rotate to LandscapeRight/Left I want to change the location of some of my buttons. Here's what I'm trying:

How to config WAMP apache server to allow cross domain requests of ajax?

apache sencha-touch cross-domain wamp

I am working on an sencha-touch-2.1.0-based application.The application deals with some cross-domain requests.