364,085 Members | 5244 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Browser Quirk: Dynamically appended checked checkbox does not appear checked (IE)

acoder
Expert Mod 10K+
P: 13,930
Problem
Dynamically appended checkbox element does not appear checked despite setting the checked property state to true or "checked".

Browser
Internet Explorer

Example
The Javascript code:
Expand|Select|Wrap|Line Numbers
  1. var cb = document.createElement("input");
  2. cb.type = "checkbox";
  3. cb.name = "checkbox1";
  4. cb.id = "cbID";
  5. cb.checked = true;
  6. obj.appendChild(cb);
Solution
Use defaultChecked instead of checked:
Expand|Select|Wrap|Line Numbers
  1. cb.defaultChecked = true;
Alternative Solution
Set the checked state after appending the checkbox:
Expand|Select|Wrap|Line Numbers
  1. obj.appendChild(cb);
  2. cb.checked = true;
More Bugs, Quirks and Inconsistencies
Aug 18 '07 #1
Share this Article
Share on Google+

Post your comment

Sign in to post your comment or Sign up for a free account.