Accessing document form elements outside a function

J

Jehan

At the end of my HTML page I have following.....

<script>

for (i = 0; i < document.section_entry.length;i++) {

// some code
}

</script>

Here it gives an error that "document.section_entry.length is null or
not a object". "section_entry" is the name of a form on my page.

When I have this same code inside a function (instead of at a global
level like how it is here) it works fine. Anyone have any ideas what
is causing the error?

Thanks in advance for any help,
Jehan
 
D

DU

Jehan said:
At the end of my HTML page I have following.....

<script>

for (i = 0; i < document.section_entry.length;i++) {

// some code
}

</script>

Here it gives an error that "document.section_entry.length is null or
not a object". "section_entry" is the name of a form on my page.

It could mean that the form object is not fully loaded into the
document. Note that your script is not a function either but rather an
immediate query about the form. type is not defined, which is a
validation syntax error. i is also defined as a global variable. You're
not using defer attribute either. All this is risky, not recommendable,
when the document is still being loaded, parsed, rendered.
When I have this same code inside a function (instead of at a global
level like how it is here) it works fine.

Because your function is most likely called once the document is fully
loaded into the browser memory... or your function is merely called when
the document is still loading... or..

Anyone have any ideas what
is causing the error?

Thanks in advance for any help,
Jehan

Without providing an url or sufficient chunks of relevant code, it's
impossible to say without actually seeing the source code.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top