Basic JS src problem

I have been building a page using in a HTML page and this was working fine. So I know the JS is correct. But I now want to separate the JS into a separate file.
In the HTML body I have,

          <script src="inputJavaScript.js"></script>

and the file inputJavaScript.js is currently in the same directory as the html file. But I can not get any response from the JS file.
I am running a WAMPserver just locally on my laptop. I thought possibly there could be an issue with the forward slash being used in my pathnames as the actual windows paths use back slashes. But I don’t think this is it because I am able to link to the CSS file and a favicon image and these all work.
Should I be including language=“javascript” type=“text/javascript” ? Like this,

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

Do I need to include a JS library or something. I doubt it since this JS was working fine when the script was in the html.

Are you viewing the HTML via “file:///page.html” or “http://localhost/page.html”?

If the former, that tends to not always work as expected.



PS. Remove language="javascript". That’s deprecated. Unless HTML5 brought it back (doubtful.)

what does that mean? response as in HTTP Response? have you checked the Error Console?

Try this:

<script src="./inputJavaScript.js"></script>

I use the latter.

Ok, I didn’t know that.

Is this bit important. I was using MDN

to learn how to do this.

I just meant that the JS file isn’t being called.

If you place an alert() in the .js file, does it not alert?

[quote=“ofeyofey, post:5, topic:197921”]

Is this bit important. I was using MDN
[/quote]Not critical, but generally advisable to use type="text/javascript".


so you don’t have it listed in your dev tool’s network section?

or does your script modifies HTML elements that are not yet gone through the HTML parser because they’re placed after the script?

@mawburn, just curious. I’ve seen the “./” before. What does that do?



1 Like

. => current directory
.. => parent directory


I actually just did that test

      <!-- <script type="text/javascript" src="inputJavaScript.js"></script> -->
      <script type="text/javascript" src="test.js"></script>

and yes it does work oddly. The original js file name is correct.

What @Dormilich said. :slight_smile:

I stab a guess at a timing problem.

(now I’m waiting for felgall’s usual advice…)

1 Like
      <script type="text/javascript" src="./inputJavaScript.js"></script>
      <!-- <script type="text/javascript" src="test.js"></script> -->

Still not working.

Not sure what that means.

Can I confirm that the JS in inputJavaScript.js does not need to be surrounded by



What does it show in the network tab of your browser for the asset?

I don’t know what the network tab is. I am using Firefox. Is this a Chrome feature. Got Chrome too

In case it is any use here are my files.

Correct. .js files should not have <script></script> tags within them. The .js file ext indicates that it is JavaScript.

Also, typically the location of the <script> tag is either just before the closing </body> tag, or within the <head> tag. Recently, there seems to be a shift towards the end </body> tag.


1 Like

Also, if you use FireFox, it’s beneficial to use a plugin called “FireBug”. Excellent at debugging code and getting the most out of error messages.



That’s a screenshot of the explorer.

Got one of the dev network? eg.