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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

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

    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:
    [CODE=javascript]var cb = document.create Element("input" );
    cb.type = "checkbox";
    cb.name = "checkbox1" ;
    cb.id = "cbID";
    cb.checked = true;
    obj.appendChild (cb);[/CODE]
    Solution
    Use defaultChecked instead of checked:
    [CODE=javascript]cb.defaultCheck ed = true;[/CODE]
    Alternative Solution
    Set the checked state after appending the checkbox:
    [CODE=javascript]obj.appendChild (cb);
    cb.checked = true;[/CODE]

    More Bugs, Quirks and Inconsistencies
Working...