By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Mozilla, written html and getElementById

P: n/a
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

The same message that would appear if I tried to get real non-existant id
table = document.getElementById ('abc-doesnotexist')
alert (table.rows.length)

Any work arounds ( Not in a position to place my own null table in source
HTML:( ) ?
Should I skip making 1.4 happy and wait for Moz 1.5+ ?

--
Richard A. DeVenezia
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"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
--
Richard A. DeVenezia

Jul 20 '05 #2

P: n/a
"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.
Jul 20 '05 #3

P: n/a
"Richard A. DeVenezia" <ra******@ix.netcom.com> writes:
"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

My guess:
You use document.write to insert context in the input stream after
the current script element. It is not parsed until after the script
tag ends.

Try ending the script tag after the document.write and start a new
script tag with the rest of the code.
This happens in a js that is being loaded in the <HEAD> tag


So, you are writing tables into the head tag? That means that
the head tag must have stopped, so the browser automatically ends
the head tag and starts the body tag.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

P: n/a
Il Wed, 10 Sep 2003 11:32:52 +0200, Lasse Reichstein Nielsen ha scritto:
"Richard A. DeVenezia" <ra******@ix.netcom.com> writes:
"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
.... So, you are writing tables into the head tag? That means that the head
tag must have stopped, so the browser automatically ends the head tag
and starts the body tag.

/L


Maybe he meant that the script tag containing that portion of code is
inside the head and not in the body, I'm just supposing.

gp
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.