Batman
Batman

Reputation: 928

CheckBox Issue in IE6

I am dynamically generating checkboxes for a popup window (displayed using AJAX) using javascript and on a button click I also need to call a function that checks all the check boxes before the popup is rendered.

All pages in use are JSPs and the popup is also included using the tag so it is generated already when the parent page gets loaded.

The problem is that I'm able to check all the custom generated checkboxes using the same function in IE7 and IE8. But it does not work for IE6.

I'm using something like:

var i;
for(i=0; i<size; i++){
     document.getElementById('chk'+i).checked = true;
}

Upvotes: 1

Views: 516

Answers (2)

Spudley
Spudley

Reputation: 168753

That code ought to work fine, even in IE6 (which, lets be honest, is a really awful browser).

However, if you have inserted those checkboxes into the page dynamically, IE6 has a known issue with dynamically added checkboxes, where it doesn't respect the .checked property.

See this page for a few possible solutions: http://bytes.com/topic/javascript/insights/799167-browser-quirk-dynamically-appended-checked-checkbox-does-not-appear-checked-ie

Hope that helps. :-)

(But my solution is: Don't support IE6. Honestly, it's usage is down to a few percent now and getting lower, so unless it's more well used by your particular demographic, just cut your losses and drop it; the remaining users will upgrade soon enough. ;-))

Upvotes: 1

DanSingerman
DanSingerman

Reputation: 36522

Without wanting to sound like a 'use jQuery' pat answer, if you were to do this with a library like jQuery, any IE6 inconsistencies would probably be nicely abstracted away.

Upvotes: 0

Related Questions