Problem with RADIO (created by DOM) in Internet Explorer

Discussion in 'Javascript' started by Raghuram Banda, Oct 21, 2003.

  1. 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.getElementById("cell1");
    for(var i=0; i < arrData.length; i++) {
    var objRadItem = document.createElement("input");
    objRadItem.type = "radio";
    objRadItem.name = "radGroup";
    objRadItem.id = "idrad_" + i;
    objRadItem.value = arrData[0];

    if(i == 1) {
    objRadItem.defaultChecked = true;
    objRadItem.checked = true;
    }
    var objTextNode = document.createTextNode(" " + arrData[1]);
    var objLabel = document.createElement("label");
    objLabel.htmlFor = objRadItem.id;
    objLabel.appendChild(objRadItem);
    objLabel.appendChild(objTextNode);

    var objBreak = document.createElement("br");

    cellId.appendChild(objLabel);
    cellId.appendChild(objBreak);
    }
    document.forms["FirstFormName"].addRadio.disabled = true;
    }

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

    Thanks in advance
    Raghuram Banda
    Raghuram Banda, Oct 21, 2003
    #1
    1. Advertising

  2. Raghuram Banda wrote:

    > 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.getElementById("cell1");
    > for(var i=0; i < arrData.length; i++) {
    > var objRadItem = document.createElement("input");
    > objRadItem.type = "radio";
    > objRadItem.name = "radGroup";
    > objRadItem.id = "idrad_" + i;
    > objRadItem.value = arrData[0];
    >
    > if(i == 1) {
    > objRadItem.defaultChecked = true;
    > objRadItem.checked = true;
    > }
    > var objTextNode = document.createTextNode(" " + arrData[1]);
    > var objLabel = document.createElement("label");
    > objLabel.htmlFor = objRadItem.id;
    > objLabel.appendChild(objRadItem);
    > objLabel.appendChild(objTextNode);
    >
    > var objBreak = document.createElement("br");
    >
    > cellId.appendChild(objLabel);
    > cellId.appendChild(objBreak);
    > }
    > document.forms["FirstFormName"].addRadio.disabled = true;
    > }
    >


    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.elements.radGroup
    as documented at

    http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/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.createElement('<input type="radio" name="radGroup">')

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Oct 21, 2003
    #2
    1. Advertising

  3. Raghuram Banda

    Guest

    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
    , Jan 17, 2005
    #3
  4. Raghuram Banda

    RobG Guest

    wrote:
    > 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
    >


    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
    RobG, Jan 18, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cmay
    Replies:
    0
    Views:
    1,113
  2. Jan C. Faerber
    Replies:
    0
    Views:
    610
    Jan C. Faerber
    Jun 30, 2009
  3. Ed Hauptman
    Replies:
    7
    Views:
    993
    Ed Hauptman
    Aug 7, 2009
  4. Thomas
    Replies:
    6
    Views:
    169
  5. wl
    Replies:
    5
    Views:
    131
    Uday Bhasker Teerdhala
    May 17, 2005
Loading...

Share This Page