Accessing document form elements outside a function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jehan

    Accessing document form elements outside a function

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

    <script>

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

    // some code
    }

    </script>

    Here it gives an error that "document.secti on_entry.length is null or
    not a object". "section_en try" 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
  • DU

    #2
    Re: Accessing document form elements outside a function

    Jehan wrote:[color=blue]
    > At the end of my HTML page I have following.....
    >
    > <script>
    >
    > for (i = 0; i < document.sectio n_entry.length; i++) {
    >
    > // some code
    > }
    >
    > </script>
    >
    > Here it gives an error that "document.secti on_entry.length is null or
    > not a object". "section_en try" is the name of a form on my page.
    >[/color]

    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.
    [color=blue]
    > When I have this same code inside a function (instead of at a global
    > level like how it is here) it works fine.[/color]

    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[color=blue]
    > is causing the error?
    >
    > Thanks in advance for any help,
    > Jehan[/color]

    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:

    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


    Comment

    Working...