...

View Full Version : createElement radio name bug with IE



A1ien51
12-20-2005, 07:19 PM
Just wondering if anyone knows a work around for IE not setting the name for a radio button when using createElement

example code



var elem1 = document.createElement("input");
elem1.type = "radio";
elem1.name = "q" + strId;
elem1.setAttribute('name',"q" + strId);
elem1.value = "1";


When you look at the code, there is no name attached to the element making it useless when you are trying to reference it.

Now I know with IE you can do:


var elem1 = document.createElement("<INPUT TYPE='RADIO' NAME='q" + strId+ "' VALUE='0'>");

But that is rather ugly solution. I am about to just do the innerHTML route to avoid all of this.

Thanks,
Eric

Pyth007
12-20-2005, 08:28 PM
Take a look at this (http://www.thunderguy.com/semicolon/2005/05/23/setting-the-name-attribute-in-internet-explorer/)...

You may also want to try this script, which I have adapted from another site that mentioned this problem in IE (although I cannot find the site now and I was stupid enough to forget to place acknowledgements in the script comments... :( ):

function attributeSet(elem, attrb, setting)
{
if(attrb.toLowerCase()=='class' || attrb.toLowerCase()=='classname')
{
elem.className=setting;
return;
}
var elemAttrb = elem.getAttributeNode(attrb);
if (elemAttrb)
{
elemAttrb.value=setting;
} else {
elem.setAttribute(attrb, setting);
}
}

Basscyst
12-20-2005, 09:49 PM
I ended up using the ugly method. After much research. What an irritating time I had making those radio buttons work. :mad:

http://www.codingforums.com/showthread.php?t=60870

Basscyst

A1ien51
12-21-2005, 04:36 AM
I ended up doing a little hack myself shortly after I posted this question . It is sort of the way Basscyst did it. I am on my way of being bald trying to figure this one out.

thanks,
Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum