Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include 2 .js files in 1 html page?

Status
Not open for further replies.

PopcornBuzzard

Programmer
Mar 26, 2003
7
US
I would like to include 2 .js files in 1 html page.

Here's what I've got in the <HEAD> section:

<script src=&quot;../includes/MenuAdditional.js&quot; type=&quot;text/javascript&quot;></script>

<script src=&quot;../includes/listMenu.js&quot; type=&quot;text/javascript&quot;></script>

For some reason, only 1 .js file is seen. The other is ignored. Any ideas?? Thanks!
 
PopcornBuzzard,

What indication do you have that you are only seeing one of the files?

Things to check:

Case
Case matters. listMenu.js is different than ListMenu.js

Function Name
Make sure that all functions are uniquely named -- regardless of the .js file containing them. If your first file has a function named &quot;wangdoodle&quot; and your second file also has a function named &quot;wangdoodle&quot;, then when you call &quot;wangdoodle&quot;, there's no telling for sure which one will be used.

Cheers,


[monkey] Edward [monkey]

Like Lovecraft? Know Photoshop? Got time for the Unspeakable?
 
For some reason, it's always the second .js file that is seen. I tried commenting out each <script> line, one at a time, and it was able to execute the script correctly for each file when I did that.

I checked the case and spelling, and that seems fine.

The functions in each .js file are uniquely named.

One note: The file that includes the .js files is actually an .asp file. Must it be an .html file?? I figured that shouldn't make a difference.
 
at the bottom of each of your files and outside any function insert an alert like

alert(&quot;Done with file 1&quot;);
and
alert(&quot;Done with file 2&quot;);

that will give you the answer wheter your files are being &quot;viewed&quot; by your page or not .

The syntax that you presented seems correct.
check the functions and or names as in previous posting.




 
Yeah, grtfercho, that's exactly how I tested whether the page could read the .js files...I stuck in some alert statments and they popped up fine, as long as only 1 <script> statement was used at a time.
 
Do you have a link of the page so people can have a look at it?

if not try this..
Save your own file from IE in a folder, once you do that go to that folder and look for the folder named the same as your file ( all the needed files are inside). Check if you have both .js files if you do then the browser can look at both files if you only get one then something is wrong with the code.
 
That's a neat idea about saving the file to a folder so you can see all the files the page uses...I'm going to remember that for the future...thanks. In this case, both of the .js files are in the folder.

I'm using MS Interdev...I wonder if there is something weird about my settings. I've also got a .CSS file that is included in the <HEAD> section and works fine, but I wonder if it is causing some sort of problem with the .js files.

I will try to create a very simple .asp page (that has lots less &quot;stuff&quot; than the problem page) that includes both .js files and see what happens.
 
Well, I just created a simple .asp page that does nothing but call functions in the 2 .js files and the page can see both files fine. So, I guess there is something strange about the original, larger .asp page. I'll go over it with a fine-toothed comb now & hopefully I'll catch something. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top