Question

So I'm trying to add attributes to a radio button input, specifically the name attribute in Javascript. I'm appending children to a main object and when I use Object.setAttribute("name", value); and subsequently check the innerHTML of the appended input, it does not even contain a name property at all!

I'm guessing I'm missing something simple or there is a way around it but I've been wrestling with this problem for quite a while with no success. I tried accessing the property directly using Object.name = value and Object.nodeName = value (that one was a random try).

Is there some sort of problem in which IE6's javascript rendering engine does not recognize setAttribute("name", value)? Is there a way around it?

Was it helpful?

Solution

Here's a workaround for dealing with IE:

http://javascript.about.com/library/bliebug2.htm

http://www.thunderguy.com/semicolon/2005/05/23/setting-the-name-attribute-in-internet-explorer/

Essentially, the method used is to create the elements on the fly instead of modifying existing elements.

OTHER TIPS

In IE, you cannot add a name attribute on dynamically created objects.

I suggest using id if unique, or a class if not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top