createElement not working in IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • onlyshanks28
    New Member
    • Oct 2008
    • 13

    createElement not working in IE

    Hi,

    I wrote a javascript code as follows

    [CODE=javascript]function fun1()
    {
    var element = document.create Element('input' );
    element.type='c heckbox';
    element.checked ='checked';
    body.appendChil d(element);


    }[/CODE]

    this code is working fine in Firefox but in IE the checkbox is creating but it is unchecked.
    I want a checked check box(It is coming in firefox)

    Help me out please
    Last edited by gits; Oct 10 '08, 11:50 AM. Reason: added code tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    try:
    element.checked = true;

    regards

    Comment

    • onlyshanks28
      New Member
      • Oct 2008
      • 13

      #3
      thanks for response

      I got it.It can be done just by writing
      element.checked ='checked';
      after append
      as follows the complete code:

      [CODE=javascript]function fun1()
      {

      var element = document.create Element('input' )
      element.type='c heckbox';
      body.appendChil d(element);
      element.checked ='checked';
      }[/CODE]
      Last edited by gits; Oct 10 '08, 11:51 AM. Reason: added code tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        That's correct, or you can use the defaultChecked property. See Dynamically appended checked checkbox does not appear checked.

        Comment

        Working...