Reputation: 311
So I have this basic Html:
<html>
<head>
</head>
<body>
<button type="button" onclick="change()">Try it</button>
<script scr="test.js" type="text/javascript"></script>
</body>
</html>
And this basic Javascript file:
function change(){
alert("asdfasdfa");
}
Both files are saved in the exact same location on my local disk. However when I open the Html file in Chrome I get the following error:
Uncaught ReferenceError: change is not defined
I have tested the script inline and that works fine, just not in an external file. I have searched this issue and so far none of the 'solutions' I have found seem to solve my problem. Thanks in advance.
Upvotes: 1
Views: 862
Reputation: 7133
Typo: Change scr
to src
:
<script src="test.js" type="text/javascript"></script>
Upvotes: 3
Reputation: 19318
There's an error in your markup that means test.js
is never loaded.
You have a typo in the script tag. The attribute src
is written scr
in your example.
Upvotes: 1