SOLUTION FOUND: Firstly, the code below DOES in fact work. Sorry about that. Moreover, my more complex code (not shown) was NOT WORKING BECAUSE MY .js SCRIPT HAD SYNTAX ERRORS IN IT. Note, these syntax errors had nothing to do with the functions I was attempting to invoke, which were the top two functions in the script. This means you must make sure your entire .js is flawless before attempting to load any of its functions. This last task was easily accomplished using http://www.jshint.com/, an online javascript parser. It's awesome.
I am trying to include a js file with javascript functions in my html file, and it isn't working. I won't claim to have tried everything, but I've tried most things. For simplicity, I have placed test.html and test.js IN THE SAME FOLDER.
test.html:
<html>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript">
alert('1!'); // for debugging
testAlert(); // supposed to pop-up alert BUT IS ERRORING OUT HERE!
alert('2'); // for debugging
alert(testStr());
alert('3'); // for debugging
</script>
<body>
The body.
</body>
</html>
test.js:
function testStr()
{
return "hello";
}
function testAlert()
{
alert('initYEAH!');
}
When I load test.html in my browser, the first debug alert pops up, but the second debug alert never does, telling me that one of two things is happening:
1) The test.js file is not being properly loaded
or
2) The test.js file is being loaded, but it is throwing some syntax error.
Can anyone tell me why I can't execute the functions in my test.js script?