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!

IE Mac

Status
Not open for further replies.

gerases

Programmer
Apr 27, 2006
29
US
Hello,

I've got this pesky problem with the IE under Mac (5.1). Here's the code.

var myTable = document.getElementById("tableID").getElementsByTagName("tbody")[0];
var myRow = document.createElement('TR');
var myTD = document.createElement('TD');
var elem = document.createElement('select');
elem.setAttribute('name', 'my_name');
myTD.appendChild(elem);
myRow.appendChild(myTD);
myTable.appendChild(myRow);

The problem is that after appending the row into the table, I can't access the element by doing the usual document.forms[0].my_name
or
document.forms[0].elements['my_name']

The only way this works is if I set the "id" attribute for the control with setAttribute('id', 'my_name') and then do document.getElementById('my_name').
 
So it seems that the forms collection is not updated after a new element is added dynamically?
 
Yes, the table is inside a form. It works in all browsers but the Mac IE.

elem.name doesn't do it. What's interesting is that when I do alert(myRow.innerHTML), everything looks fine. The element has the right name attribute. Here's the output of the alert:

<TD><SELECT name=my_name type=select></SELECT></TD>
 
The problem is that after appending the row into the table, I can't access the element by doing the usual document.forms[0].my_name

How do you know you cannot access it? What errors do you get?

Does this change if you populate the select element with some options?

Dan




Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
What I do in the code is create a select element and then populate it from an array. It's the populate stage where I get the error -- I get something like "undefined" whenever I try to access it.
 
I get something like

Can you give a more exact error. Saying it's "something like" doesn't really help.

What happens if you run it in Firefox? Does it give any meaningful errors in the JS console?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Ok, after I add the row to the table, I do:

alert(document.forms[0].my_name);

which generates precisely this: "undefined".

FF and everything else work fine. No errors.
 
Yep, assigning the element an id and using it to refer to the element works fine.
 
You know, just a couple of minutes ago, we decided not to support that browser. That was just one of the quirks of the browser. There's many more (regular expressions for instance). I want to thank you for following up on this. It's REALLY very nice of you.
 
Yeah, I was going to say, IE for Mac is well.... a lost cause. I've had stuff work great and mostly work on other browsers, but IE for Mac seems to always give me issues.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top