checkbox not checked with setAttribute

Attempting to set a generated checkbox element to a checked status fails in IEwin6:it doesn't matter whether setAttribute is called before or after appending.

Don't have a workaround besides using el.checked=true after appending (which is precisely want I wanted to avoid!)

Same problem doesn't affect disabled attribute. PS. see also testpage elements for select.selected and select.size

Test page Workaround is not included
Reported by: Andy Taylor.

Explorer 5-6 Windows, Explorer 7 | Reported on 2 February 2007.

This site is no longer maintained. I’m sorry, but it’s just too much work for too little return. You can continue to browse old bug reports, though.




Search reports by browser:

Atom RSS

Comments

(Add your own)

1 Posted by Tino Zijdel on 2 February 2007 | Permalink

That's not really a bug, you should use setAttribute('defaultChecked', 'checked'); before appending.
But why would you want to avoid element.checked=true?

2 Posted by Gérard Talbot on 12 February 2007 | Permalink

Correct! That is not a bug.

This testcase works with MSIE7:

http://www.gtalbot.org/DHTMLSection/AppendingCheckedCheckbox.html

DOM 2 HTML says "checked represents current state of form control" while defaultChecked represents the default, the start status of the form control.

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-30233917

I must point out that the provided testcase by Andy T. is not a reduced testcase and not a self-evident testcase. Also, modifying the DOM tree on a window.onload is *not* a recommendable thing to do as the window and document.body are loaded asynchronuously.

Gérard