Accessing document form elements outside a function

Discussion in 'Javascript' started by Jehan, Sep 10, 2003.

  1. Jehan

    Jehan Guest

    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
     
    Jehan, Sep 10, 2003
    #1
    1. Advertising

  2. Jehan

    DU Guest

    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/doctorunclear/Netscape7/Netscape7Section.html
     
    DU, Sep 10, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jessica Weiner
    Replies:
    2
    Views:
    413
  2. Gerald Aichholzer
    Replies:
    2
    Views:
    2,511
    Gerald Aichholzer
    Jun 27, 2006
  3. Steve Blinkhorn

    accessing static variables from outside their function

    Steve Blinkhorn, May 10, 2006, in forum: C Programming
    Replies:
    12
    Views:
    555
    Steve Blinkhorn
    May 11, 2006
  4. Krzysztof Poc

    outside type, outside function

    Krzysztof Poc, Feb 3, 2012, in forum: C++
    Replies:
    1
    Views:
    288
    Victor Bazarov
    Feb 7, 2012
  5. Replies:
    4
    Views:
    188
Loading...

Share This Page