ngindk
08-01-2002, 09:03 PM
Hi - cool forum! This is my first post but *heck* here goes:
As far as I know a friend of mine put all his javascripts-functions in an external file and then refers to it from his "normal" html file.
How can I do that?
I've tried to ask him, but he has'nt answered me yet, so hopefully someone in here answers before him...
In advance - THX!
ConfusedOfLife
08-01-2002, 09:17 PM
well, as a matter of fact it's very easy! You open a free document, whatever it is! Then you type your functions or variables that you like, then you save the file with the "js" extension ( Note : do not write your functions in the external file between <script> .... </script>, it's no need to do that for an external file).
Then you can call that file in any html file that you like by typing:
<script language="javascript" src="TheNameOfFile.js">
</script>
Notice that when you use a <script> tag for reading an external file, you shouldn't put any other statements between that tag and it's closing ( </script> ) tag.
Roy Sinclair
08-01-2002, 09:48 PM
Notice that when you use a <script> tag for reading an external file, you shouldn't put any other statements between that tag and it's closing ( </script> ) tag.
It should also be noted that the file with the javascript in it should have no html in it. That means no <script> </script> tags, no <!-- --> comment tags or anything else. What it should contain is javascript, only javascript.
ngindk
08-01-2002, 10:21 PM
Thx for the quick responce!! :thumbsup:
I just have one question - maybe I'm a bit 'slow' but can't get it to work 100%
I've done all you've mentioned so far, but how do I call a specific function?
The way I did it is I've made different function with unique names etc, placed in that .js file. How do I then call e.g.
Function validateDiz();
from my html file? Is it
<script language="javascript" src="MyFile.js">
validateDiz();
</script>
or is it done in another way??
Once again - thx for fast responce!;)
mordred
08-01-2002, 11:22 PM
That's the proper syntax I believe:
<script language="javascript" type="text/javascript" src="MyFile.js"></script>
<script language="javascript" type="text/javascript">
validateDiz();
</script>