Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Accessing document form elements outside a function

Reply
Thread Tools

Accessing document form elements outside a function

 
 
Jehan
Guest
Posts: n/a
 
      09-10-2003
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
 
Reply With Quote
 
 
 
 
DU
Guest
Posts: n/a
 
      09-10-2003
Jehan wrote:
> 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/doctorunc...e7Section.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
outside type, outside function Krzysztof Poc C++ 1 02-07-2012 04:06 PM
help with pix inside->outside + dmz->outside + inside->outside->dmz Jack Cisco 0 09-19-2007 01:57 AM
Accessing input fields declared outside the form Jessica Weiner ASP .Net 2 07-05-2006 05:35 AM
XSLT: iterating all child elements and accessing homonymous childrenin sibling elements Gerald Aichholzer XML 2 06-27-2006 03:46 PM
accessing static variables from outside their function Steve Blinkhorn C Programming 12 05-11-2006 11:54 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57