Results 1 to 7 of 7

Thread: Unable to call external script

  1. #1
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Unable to call external script

    I am using the calender javascript found at: http://www.dynamicdrive.com/dynamicindex6/clock3.htm

    The script requires me to include <body onLoad="goforit()">. The script runs fine if the script is inside of the actual file; however, when I put the script in an external file, the script fails to run and I get the error

    "Object expected" at the <body onLoad="goforit()"> line.

    I'm thinking this has to do with the fact the body can't find the goforit() function because it is in an external file. What would be the best solution to this problem other than including the script inside the file itself?

  2. #2
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Makesure that the body onload tag is placed AFTER the external script is called.

    cr3ative
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  3. #3
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by cr3ative
    Makesure that the body onload tag is placed AFTER the external script is called.

    cr3ative
    It doesn't work, unless I am misconceiving what you mean by placing the body onload tage after the external script. The external script is inside the body tag itself. The only position I can place the gofotit() function is at the beginning of the body tag itself.

  4. #4
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Make sure the tags are in this order:

    <script src="whatever.js"></script>

    <body onload="javascript:goforit();">

    and not the other way around.
    cr3ative
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  5. #5
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You'll have to forgive me. My javascript skills are horrible. This is my code so far:

    <html>
    <head>
    <script type="text/JavaScript" src="Library/Calender.js"></script>
    </script>
    <title>Untitled Document</title>
    </head>
    <body onLoad="javascript: goforit()">
    </body>
    </html>

    First, I still get the object expected error at the body onload line. Second, how can I place the calender/time where I want it?

    Thanks.

  6. #6
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Before we go too far, we need to sort out the error

    1. Make sure your host is not case-sensitive. If it is, re-enter the .js filename with the capitalization found on the server.

    2. Make the address absolute, not relative, so instead of library/calender.js, change this to http://www.yourhost.com/yourpage/library/calender.js

    3. Try changing javascript: goforit() with javascript:goforit();

    cr3ative
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  7. #7
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Okay, I figured it out. I used the code:

    <html>
    <head>
    <title>Untitled Document</title>
    </head>
    <body onLoad="goforit()">
    <script src="Library\Calender.js">
    </script>
    <span id="clock"></span>
    </body>
    </html>

    One of the problems was I included the tags <script> and </script> in the actually .js file. So when I ran the file, I had two <script></script> tags. I also included the <span id="clock"></span> part inside of the script itself, which could have resulted in an unknown error. Either way, I finally got the script working.

    Thanks for your help cr3ative

Bookmarks

Posting Permissions

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