hi,
i have this html code:
[CODE]<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”content-type” content=”text/html;charset=utf-8″>
<title>Date & Time</title>
<script type=”type/javascript” src=”date-time.js”></script>
</head>
<body>
<h1>Date & Time</h1>
<p>It is currently <span id=”output”>now</span>.</p>
</body>
</html>
and have this javascript linked to it.
[CODE]//tell the browser to run this script when the page has finished loading
window.onload = insertDateTime;
//insert the date & time
function insertDateTime()
{
//ensure a DOM-aware user agent
if (!document.getElementById) return;
if (!document.createTextNode) return;
//create a date-time object
var oNow = new Date();
//get the current date & time as a string
var sDateTime = oNow.toLocaleString();
//point to the target element where we want to insert the date & time
var oTarget = document.getElementById(‘output’);
//make sure the target is found
if (!oTarget) return;
//delete everything inside the target
while (oTarget.firstChild)
{
oTarget.removeChild(oTarget.firstChild);
}
//use the date-time string to create a new text node for the page
var oNewText = document.createTextNode(sDateTime);
//insert the new text to the span
oTarget.appendChild(oNewText)
}
for some reason i don’t get the response from the html that i’m supposed to get. like the date is not displaying. i wonder what’s wrong. any clue?