Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

createelement / name

Status
Not open for further replies.

gerases

Programmer
Apr 27, 2006
29
US
Weird behavior in Safari:

myRow = createElement('tr');
myTD = createElement('td');

elem = createElement('select');
elem.name = 'my_name';

myTD.appendChild(elem);
myRow.appendChild(myTD);

alert(myRow.innerHTML) gives:

<TR>
<TD>
<SELECT></SELECT>
</TD>
</TR>

Bottom line, the name attribute is missing. Anyone experienced this?

 
Sorry, I was typing from my memory and forgot "document." before createElement...
 
This is how it's done.
Code:
myRow = createElement('tr');
myTD  = createElement('td');

elem  = createElement('select');
elem.[b]setAttribute('name', 'my_name');[/b]

myTD.appendChild(elem);
myRow.appendChild(myTD);

alert(myRow.innerHTML) gives:

M. Brooks
 
Nope, I actually tried that before I posted. The name is still missing... Did you try it in your Safari?
 
Sorry, it did work when I created a simple case. Something within my more complicated case is messing it up, but I'll figure it out. Thanks A LOT for the tip!!!
 
So how do I do it across browsers without sniffing?

In IE it's: elem = createElement("<select name='my_name'>")
In FF: elem = createElement('select'); elem.name = 'my_name'
In Safari: elem = createElement('select'); elem.setAttribute('name', 'my_name');

Safari doesn't error back on elem.name = 'my_name' and you can actually query the property back, but it doesn't write it in the resulting HTML.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top