run javascript from separate file

In order to run javascript from a separate file:

  1. Cut the script between your script tags and save it as a separate file with the .js extension.
  2. Then use the src tag to give the file's location

In the example below I have called my file datafile.js

<script type="text/javascript"
src="datafile.js">
</script>

For a much more in depth look at how to run javascript from a separate file see this helpful tutorial:

http://www.javascript.about.com/library/bltut13.htm

13/02/2009