Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Problem with RADIO (created by DOM) in Internet Explorer

Question posted by: Raghuram Banda (Guest) on July 20th, 2005 11:17 AM
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[i][0];

if(i == 1) {
objRadItem.defaultChecked = true;
objRadItem.checked = true;
}
var objTextNode = document.createTextNode(" " + arrData[i][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

Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
July 20th, 2005
11:17 AM
#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.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[i][0];
>
> if(i == 1) {
> objRadItem.defaultChecked = true;
> objRadItem.checked = true;
> }
> var objTextNode = document.createTextNode(" " + arrData[i][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;
> }
>[/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.elements.radGroup
as documented at

http://msdn.microsoft.com/workshop/...ties/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/


obsidian8@hotmail.com's Avatar
obsidian8@hotmail.com
Guest
n/a Posts
July 23rd, 2005
04:38 PM
#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


RobG's Avatar
RobG
Guest
n/a Posts
July 23rd, 2005
04:39 PM
#4

Re: Problem with RADIO (created by DOM) in Internet Explorer
Join Bytes! 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

 
Not the answer you were looking for? Post your question . . .
189,086 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors