469,304 Members | 2,192 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

DOM objects immediately available to script?

Given the following in the <body> of an HTML page:

<form name="test" action="action">
<input name="test1" value="abc">
<script type="text/javascript">
alert(document.forms['test'].elements['test1'].value);
</script>

I have two questions:

1. Is there anything in the specs/standards that says the <form> and <input>
objects must be available for reference in the DOM as soon as they are
parsed in the document, so that the script will succeed? I couldn't find
anything.

2. If nothing is in the specs/standards, then does anyone know of any
browsers which would not make the objects available for script immediately?
I'm wondering if, for example, a browser would only make the DOM available
to script once it is fully loaded and parsed?

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Dec 9 '05 #1
1 1339
Matt Kruse said the following on 12/8/2005 7:45 PM:
Given the following in the <body> of an HTML page:

<form name="test" action="action">
<input name="test1" value="abc">
<script type="text/javascript">
alert(document.forms['test'].elements['test1'].value);
</script>

I have two questions:

1. Is there anything in the specs/standards that says the <form> and <input>
objects must be available for reference in the DOM as soon as they are
parsed in the document, so that the script will succeed? I couldn't find
anything.
No.
2. If nothing is in the specs/standards, then does anyone know of any
browsers which would not make the objects available for script immediately?
None that I know of. May be others though that are not on Win based
systems that know/have one that doesn't.
I'm wondering if, for example, a browser would only make the DOM available
to script once it is fully loaded and parsed?


The only time you can be sure that the DOM is available is indeed to
wait until it is fully loaded and parsed. Trying to access it before
then is going to lead into problems.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 9 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by user | last post: by
2 posts views Thread by Weston C | last post: by
8 posts views Thread by vvenk | last post: by
reply views Thread by Matti Airas | last post: by
20 posts views Thread by walterbyrd | last post: by
6 posts views Thread by Tim Hunter | last post: by
66 posts views Thread by karthikbalaguru | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.