I started building a new skin from the html 5 boilerplate. On the user/login menu, when the page loads, I'd like to display the output of a simple javascript clock I wrote. I am new to skinning and javascript, so this may be simple and I just don't know.
Outside the skin elements, just below an identical reference to main.js, I have referenced the external clock.js file (which is in the skin's js folder):
<script type="text/javascript" src="<%skinpath %>""js/clock.js"></script>
and the javascript file references the correct div id in the skin "date".
the script itself is functional, but will not display the clock in the skin, I would like the clock to fire on the page load, and I don't know how to do it. Here is the entire js file, what am I missing, please help.
clock.js:
function clock() {
var today = new Date();
var day = today.getDate();
var month = today.getMonth() + 1;
var year = today.getFullYear();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
var ampm;
// Set ampm
ampm = apMeridian(h);
// Format the hours
h = formatHours(h);
// Format minutes and seconds
m = formatMS(m);
s = formatMS(s);
document.getElementById("date").innerHTML = day + " " + month + " " + year + " " + h + ":\
" + m + ":" + s + " " + ampm;
t = setTimeout(function () { clock() }, 250);
}
function formatHours(i) {
if (i >= 13) {
i = i - 12;
}
else if (i = 0) {
i = 12;
}
return i;
}
function formatMS(i) {
if (i < 10) {
i = "0" + i;
}
else { }
return i;
}
function apMeridian(i) {
var ap;
if (i <= 11) {
ap = "am";
}
else {
ap = "pm";
}
return ap;
}
Thank you for your help!