Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    can't get a simple global variable to work

    Hello,

    I can't understand why this would not work.

    <script blah blah>
    <!--
    var mainForm = document.search;

    function blah() {
    mainForm.text.value = "blah";
    }

    -->
    </script>

    it errors saying null or not an object. ??

    the only way i got this to work was to include
    "var mainForm = document.search" in every function


    thanks
    hogtied

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Atlanta, GA.
    Posts
    313
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Without seeing the rest of the code I will have to assume
    1)The code is in the HEAD section of your html.
    2)You have a Form named "search"

    If this is the case then "document.search" does not exist until the BODY of the document is parsed.

    Try
    <BODY onLoad="var mainForm = document.search;">

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    Spain
    Posts
    420
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wouldn't it be better...

    <body>
    <script>var mainForm = document.search</script>

    then the function can already run even if there's a big image in the page still downloading?
    Don't resist to assimilation. Billions of Borgs can't be wrong!

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes the script is in the head and I do have a form called search.

    What your saying makes since in why it does not work.

    Thanks

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    neiter one of these worked.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Atlanta, GA.
    Posts
    313
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try placing the script after the form

    <body>
    <form name="search">
    </form>
    <script>var mainForm = document.search</script>
    </body>

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks roy that worked


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •