views:

160

answers:

2

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?

+1  A: 

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

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

happytime harry
So how do I make multiple radio buttons part of the same grouping?
C Bauer
Are you dynamically creating the buttons or moving them around?
happytime harry
My mistake I completely forgot to mention these are checkboxes and radiobuttons! I put that in the tags but forgot to mention it, sorry!
C Bauer
Thats fine. If you are dynamically creating them, I would suggest hardcoding one for each group you want with name intact (hidden or offscreen) and then cloning that node to do as you wish.
happytime harry
+1  A: 

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.

Tereno
Thank you, one of these links helped me realized what I was doing wrong in the workarounds. I was about to storm out of the office in frustration, thanks so much.
C Bauer