Reputation: 27673
I have a .js file with:
function date()
{
document.getElementById("id1").innerHTML = Date();
}
And a page with:
<p id="id1"></p>
<button type="button" onclick="date()">Click here</button>
But clicking on it doesn't do anything. What's missing?
Upvotes: 1
Views: 955
Reputation: 270
I found a problem here:
First, you need to create a Date object, like so:
var d = new Date();
Then use getDate()
, getMonth()
, and so on...
var full = d.getMonth + 1; // getMonth returns 0 - 11
full += "/" + d.getDate;
full += "/" + d.getFullYear;
document.getElementById("id1").innerHtml = full;
Also, don't forget to include <script src="script.js"></script>
in your head.
Upvotes: 0
Reputation: 896
just add
<script type='text/javascript' src="path_to_js_file"></script>
on top of your html page
Upvotes: 2