0

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.

1
  • Should the src say date_button_function.js? Commented Oct 29, 2011 at 17:11

1 Answer 1

3

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"

Sign up to request clarification or add additional context in comments.

3 Comments

The end tag for the head element is optional, so that has nothing to do with it.
The head opening and closing tags are optional, but if you open you must close it.
Yeah they are optional, if you still live in the 90's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.