...

View Full Version : externalising js code



suhayda
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
src="java_script/myfile.js"></SCRIPT>

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,

Peter

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

suhayda
03-12-2004, 09:38 AM
...

Kor
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

suhayda
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
src="java_script/myjsfiles.js"></SCRIPT>

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.

Peter

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum