What's up experts. I have a problem that's driving me crazy.. I can't get any external javascript files to link to any of my pages.

They work perfect if I put it all in the head section but as soon as I put the JavaScript into an external file and try to link to it, it doesn't work. I'm pretty new to javascript but this is 101 stuff and I've literally spent hours searching through forums & trying to make it work.

Sorry if this is a stupid question that's been answered before but like I said, I couldn't find anything online to help me out. Hopefully someone can help me & maybe some other people that are having this problem (I'm sure I'm not the only one)..

I made sure there are no script tags in the external file and I'm linking them the standard way in the head section-
<script type="text/javascript" src="javascript_test.js"></script> , I have the
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> linked before it, and I checked like 100 times that it was in the right folder (the same as the index.html) and had the correct name. Again, the javascript works fine when I put it all in the header; the link is the problem.

Any ideas? Thanks.

Do you have this site online so that we can inspect it?

No, I'm just using my local server right now. I have no clue how or why, but after all this time I just got it to work..

I did a simple online tutorial from here: http://www.mkyong.com/javascript/how-to-link-an-external-javascript-file/ which had me create an external js file with an alert function. I put the external link in the body, like instructed, and the alert worked so I pasted the other js that wouldn't work before into the new external js file with the alert function and all of a sudden that started working as well. After that I transfered the link from the body to the head to test it and it's still working fine now. I just have no idea why..

I just wish I knew why it works now so I could help some other people that are having a hard time like I was.. Hopefully the links will consistantly start working now also..

Any ideas of how I just got it to work?

Most likely you had a syntax error somewhere. Leaving out one character in an important part of your JavaScript code can render the code useless.

Member Avatar

If you want jquery to work with code in the ext file, put it before the ext file:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="javascript_test.js"></script> , I have the

I've gone from placing these in the head, to placing them at the bottom of the page, just before

</body>

That way I don't have to worry about the document ready stuff.

Thanks for the replies guys. Yea it probably was just a small syntax error somewhere I didn't notice. That's a good idea to put it at the end of the body section so everything loads first, I'll start trying that out if it ever doesn't work in the head.