Forum Moderators: open
<body onLoad="clock()"> to start a running clock that is displayed using javascript, but according to the XHTML 1.0 Transitional standard it's not a valid attribute! is there a way to work around this problem? i've tried starting the clock like this: <body>
<script language="javascript" type="text/javascript">
clock();
</script>
<script language="javascript" type="text/javascript">
<!--
var digital = new Date()
function clock()
{
if (!document.all &&!document.getElementById) return;
var hours = digital.getHours();
var minutes = digital.getMinutes();
var seconds = digital.getSeconds();
digital.setSeconds( seconds+1 );
if (hours <= 9) hours = "0" + hours;
if (minutes <= 9) minutes = "0" + minutes;
if (seconds <= 9) seconds = "0" + seconds;
dispTime = hours + ":" + minutes + ":" + seconds;
if (document.getElementById)
document.getElementById("TIME").innerHTML = dispTime
else if (document.all)
TIME.innerHTML = dispTime;
setTimeout("clock()", 1000);
}
//-->
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">//<![CDATA[
var digital = new Date()
function clock() {
if (!document.all &&!document.getElementById) return;
var hours = digital.getHours();
var minutes = digital.getMinutes();
var seconds = digital.getSeconds();
digital.setSeconds( seconds+1 );
if (hours <= 9) hours = "0" + hours;
if (minutes <= 9) minutes = "0" + minutes;
if (seconds <= 9) seconds = "0" + seconds;
dispTime = hours + ":" + minutes + ":" + seconds;
if (document.getElementById)
document.getElementById("TIME").innerHTML = dispTime
else if (document.all)
TIME.innerHTML = dispTime;
setTimeout("clock()", 1000);
}
//]]></script>
</head>
<body onload="clock();">
<div id="TIME">
</div>
</body>
</html>
application/xhtml+xml - not when you are serving it with text/html. However, you are correct in that you should remove the comments in XHTML to allow for any future change of mime type.
[edited by: encyclo at 12:08 pm (utc) on Aug. 25, 2004]