Help - Search - Members - Calendar
Full Version: Moving Javascript to separate file
HTMLHelp Forums > Programming > Client-side Scripting
philwinter
Hello, I recently downloaded a Javascript routine to rotate images on my web pages. It works quite well, but requires the main Javascript routine to be in the <head> of the page - about 165 lines of code. When I run the HTML validator on the page, every line of Javascript produces and error. To avoid this, and to streamline my markup, I would like to move this Javascript routine to a separate file, but not knowing Javascript, I don't know how to do this. Here's the "calling" code in the <body>:

<script type="text/javascript">
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder) (the comment wrapped in this window)
new fadeshow(fadeimages, 200, 167, 0, 2000, 1, "")
</script>

I know that the variables mentioned above have to be passed externally when the Javascript is a separate file, I just don't know how to do it.

Any help will be greatly appreciated!

Phil
pandy
Copy the code to a file and name it something.js. Do NOT include the script tags, they are HTML. Then link to it like so (in HEAD).

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


http://htmlhelp.com/reference/html40/special/script.html

QUOTE

I know that the variables mentioned above have to be passed externally when the Javascript is a separate file, I just don't know how to do it.

Sorry. Don't follow that.
philwinter
Hi Pandy,

Thank you so much. That did it. The comment about passing variables hearkens back to my Fortran programming days many years ago.

Thanks,

Phil
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.