Problem with RADIO (created by DOM) in Internet Explorer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raghuram Banda

    #1

    Problem with RADIO (created by DOM) in Internet Explorer

    Hi All,

    The following is the function I used to create RADIO buttons using DOM.
    It works fine with Netscape but not with IE.
    function addGroup3Radio( ) {
    var cellId = document.getEle mentById("cell1 ");
    for(var i=0; i < arrData.length; i++) {
    var objRadItem = document.create Element("input" );
    objRadItem.type = "radio";
    objRadItem.name = "radGroup";
    objRadItem.id = "idrad_" + i;
    objRadItem.valu e = arrData[i][0];

    if(i == 1) {
    objRadItem.defa ultChecked = true;
    objRadItem.chec ked = true;
    }
    var objTextNode = document.create TextNode(" " + arrData[i][1]);
    var objLabel = document.create Element("label" );
    objLabel.htmlFo r = objRadItem.id;
    objLabel.append Child(objRadIte m);
    objLabel.append Child(objTextNo de);

    var objBreak = document.create Element("br");

    cellId.appendCh ild(objLabel);
    cellId.appendCh ild(objBreak);
    }
    document.forms["FirstFormN ame"].addRadio.disab led = true;
    }

    Can any one help me to come out of this problem.

    Thanks in advance
    Raghuram Banda

  • Martin Honnen

    #2
    Re: Problem with RADIO (created by DOM) in Internet Explorer



    Raghuram Banda wrote:
    [color=blue]
    > The following is the function I used to create RADIO buttons using DOM.
    > It works fine with Netscape but not with IE.
    > function addGroup3Radio( ) {
    > var cellId = document.getEle mentById("cell1 ");
    > for(var i=0; i < arrData.length; i++) {
    > var objRadItem = document.create Element("input" );
    > objRadItem.type = "radio";
    > objRadItem.name = "radGroup";
    > objRadItem.id = "idrad_" + i;
    > objRadItem.valu e = arrData[i][0];
    >
    > if(i == 1) {
    > objRadItem.defa ultChecked = true;
    > objRadItem.chec ked = true;
    > }
    > var objTextNode = document.create TextNode(" " + arrData[i][1]);
    > var objLabel = document.create Element("label" );
    > objLabel.htmlFo r = objRadItem.id;
    > objLabel.append Child(objRadIte m);
    > objLabel.append Child(objTextNo de);
    >
    > var objBreak = document.create Element("br");
    >
    > cellId.appendCh ild(objLabel);
    > cellId.appendCh ild(objBreak);
    > }
    > document.forms["FirstFormN ame"].addRadio.disab led = true;
    > }
    >[/color]

    What is not working with IE? I guess the radio buttons are inserted
    fine, the only thing that IE/Win doesn't support is then to allow access to
    document.forms. formName.elemen ts.radGroup
    as documented at

    http://msdn.microsoft.com/workshop/a...ies/name_2.asp
    which explains that you cannot set name on elemens created dynamically
    with createElement. The suggestion there is to use the IE only
    document.create Element('<input type="radio" name="radGroup" >')

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • obsidian8@hotmail.com

      #3
      Re: Problem with RADIO (created by DOM) in Internet Explorer

      Martin,

      I tried your solution for the radio buttons and it worked like a charm!
      I must have looked at every posting on this site for javascript and
      radio buttons and yours is the only one that worked. Many thanks!
      Melvin Morris

      Comment

      • RobG

        #4
        Re: Problem with RADIO (created by DOM) in Internet Explorer

        obsidian8@hotma il.com wrote:[color=blue]
        > Martin,
        >
        > I tried your solution for the radio buttons and it worked like a charm!
        > I must have looked at every posting on this site for javascript and
        > radio buttons and yours is the only one that worked. Many thanks!
        > Melvin Morris
        >[/color]

        So because IE doesn't implement the W3C DOM correctly, you will use an
        IE-only method to do something that is well supported on most other
        browsers, and certainly all the other mainstream ones?

        What was wrong with the more widely supported innerHTML solution
        proposed yesterday?

        You could try detecting IE and creating elements using their
        innerText-like solution, but innerHTML is pretty widely supported and
        would not require such silliness.

        --
        Rob

        Comment

        Working...