"Richard A. DeVenezia" <ra******@ix.netcom.com> wrote in message
news:bj************@ID-168040.news.uni-berlin.de...
"Richard A. DeVenezia" <ra******@ix.netcom.com> wrote in message
news:bj************@ID-168040.news.uni-berlin.de... Mozilla (1.4 win2k) doesn't like this
document.write ('<TABLE ID="abc"><TR><TD></TD></TR></TABLE>')
table = document.getElementById ('abc')
alert (table.rows.length)
I see in JS Console, Error: table has no properties
This happens in a js that is being loaded in the <HEAD> tag
A table element within the HEAD of a document would be invalid so if the
function is called within the head it is unrealistic to expect it to
work. But I would be expect timing problems with this code anyway as
the browser may not get a chance to fully set up the objects created
with the document.write statement before it is references. (Indeed I
recall that at least one browser delays document.write output until the
completion of the current script block)
It would probably be safer to use DOM node insertion methods to create
and insert a valid table structure. Then you would have a reference to
it prior to inserting it and would not have to use getElementById at all
(or give the table an ID). Alternatively you would probably have to
split the code with the document.write inserting the HTML inline and
another "init" function being called onload (or with a timeout).
Richard.