DOM objects immediately available to script?

M

Matt Kruse

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?
 
R

Randy Webb

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top