Question

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?

Was it helpful?

Solution

just add

<script type='text/javascript' src="path_to_js_file"></script>

on top of your html page

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top