mike
mike

Reputation: 23811

Calling JavaScript function loaded from remote file

I am just getting started with HTML/JavaScript, and I have a simple question. I am attempting to call a js function from a separate script source, but am having a bit of trouble. My function script (date_button_function.js) reads:

function displayDate()
{
    document.getElementById("date").innerHTML=Date();
}

In order to call on this function, my code looks like this:

<html>
<head>
<script type="text/javascript" src="date_button_functoin.js"></script>
<body>
<h1>Testing the Date</h1>
<p id="date">Click below to see the date.</p>
<button type="button" onclick="displayDate()">Display Date</button>
</body>
</html> 

When I actually write out the displayDate function in the HTML script, it runs just fine. However, when calling the function, it does not work. If someone could let me know my syntax error, that would be great.

Upvotes: 0

Views: 4437

Answers (1)

Deleteman
Deleteman

Reputation: 8690

You're not closing your head tag, that's probably your issue there. Also, as stated on the comments, the name of the js file is wrong, should read "date_button_function.js" instead of "date_button_functoin.js"

Upvotes: 3

Related Questions