View Full Version : externalising js code

03-12-2004, 09:30 AM
I am creating a travel website and have a ton of javascript that I need to load in my website. for some reason when I use

<SCRIPT language=javascript

my site gives me a bunch of errors. travel_grove.php is my general layout. I pull in the center piece as needed using php. One such center piece is set_form.html, which is basically a reworked search box from another travel site :).

well anyways I would like to post the two files,if anyone can extract the javascript code from the two files and repost them here along with a brief explanation about how you did it so I can actually learn something, that would be more than awesome.... I am such a rookie, dang....:)

Well thanks anyways,


03-12-2004, 09:35 AM
When you externalise js code, you should remove the "<!--" (comment-tags)

03-12-2004, 09:38 AM

03-12-2004, 09:44 AM
... because <!-- comments are HTML comments. As long as your code is placed within the HTML page, it will be ok, but when you move the code inside an external, you have to remove all the HTML comments and, of course, the marks <script></script>

If you want to insert comments inside the javascript code, use

//insert comment here

03-12-2004, 10:02 AM
great thank you very much... this works very nicely...

On my travel site I use a simple php code to load the search pieces. Every search piece has tons of Javascript coding and I need to export them all.
My question is:

can I import the HTML page with the:

<SCRIPT language=javascript

code inside of it?or would I need to have some js statement on my main page saying that if hotel page is called then call hotel.js if car.html is called then call car.js etc.

Or can i just put down on my car.html

<SCRIPT language=javascript
src="java_script/car.js"></SCRIPT> ... etc.

Again thanks for your help.


03-12-2004, 01:43 PM
I don't quite understand.. you want to import a HTML page using javascript? can u detail, please?