PDA

View Full Version : Unable to call external script



Heero
10-21-2004, 08:16 PM
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?

cr3ative
10-22-2004, 05:40 AM
Makesure that the body onload tag is placed AFTER the external script is called.

cr3ative

Heero
10-23-2004, 04:54 PM
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.

cr3ative
10-23-2004, 04:59 PM
Make sure the tags are in this order:

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

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

and not the other way around.
cr3ative

Heero
10-23-2004, 07:34 PM
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.

cr3ative
10-24-2004, 07:27 AM
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

Heero
10-24-2004, 04:12 PM
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 :)