Click to See Complete Forum and Search --> : Linking to script file


November 5th, 1999, 02:10 AM
I want to place all my scripts into one file and link this file to my web pages to use the scripts, but I can't seem to make it work. Anyone know how?
Tried this to link the script file:
<script ID="S1" language="JavaScript" src='MyScripts.js'></script>
then tried to use a function:
<script language="JavaScript"> S1.MyFunction() </script>

Palli
November 5th, 1999, 11:55 AM
Hi
You donīt have to use:
<script language="JavaScript"> S1.MyFunction() </script>

Just put your scripts in one file and add something like this to your page:
<SCRIPT LANGUAGE="JavaScript" SRC="myscripts.js">
</SCRIPT>

and call those functions like they were on the same page.
I have been doing this for long time and it has always worked for me.

best regards
Palli

November 7th, 1999, 04:57 PM
Thanks for the reply Palli, tried it the way you stated but it dosen't work.

Palli
November 7th, 1999, 05:39 PM
Which error comes up when you try to run the page with the javascript. Is your page on the net so I can browse to it and see what it wrong with it?

Palli

November 7th, 1999, 07:29 PM
Palli I got it working. Thanks for your help. One question though, I can make the functions work by calling them like so <a onclick="myFunction"> but the functions still won't work when they are inline:
<script language="javascript" src="myScript.js">
myFunction();
</script>
Is it possible to make them work this way?

Palli
November 7th, 1999, 07:51 PM
Hi again.
src="myScripts.js" tells the page to look for scripts at that location. If you want to have a function on your page than you can create another <script>

like this:
<script language="javascript">
myFunction()
</script>
and leave out src="myscript.js" part.

hope this will help
Palli

November 7th, 1999, 08:56 PM
Everything works perfect now thanks Palli!