Date and Time code not loading

BCMG76

Active Member
Joined
Apr 10, 2010
Messages
45
Reaction score
0
Hi guys can you have a look at this code, when i try to load it won't open in my browser, what am i doing wrong here?
<!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">
<head>
<title> date and time</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="js_styles.css" type="text/css" />


<script type="text/javascript">
/* <![CDATA[ */
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function getcurrentdate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds

var cdate="<big><font color='800000' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn
+"</b></font></big>"
if (document.all)
document.all.clock.innerHTML=cdate
else
document.write(cdate)
}
if (!document.all)
getthedate()
function showdate(){
if (document.all)
setInterval("getcurrentdate()",1000)
}

/* ]]> */
<!--HIDE FROM INCOMPATIBLE BROWSERS
// STOP HIDING FROM INCOMPATIBLE BROWSERS-->
</script>
<body>
<CENTER><span id="clock"></span></CENTER><BR>
onLoad="showdate()"
</body>
</head>
</html>
 
But i did close the head and the body was also opened and closed, where actually are you referring to?
 
Last couple of lines should be:
</script>
</head>
<body>
<CENTER><span id="clock" onLoad="showdate()"></span></CENTER><BR>
</body>
</html>

And not:
</script>
<body>
<CENTER><span id="clock"></span></CENTER><BR>
onLoad="showdate()"

</body>
</head>
</html>
 
Last edited:
Code:
<CENTER><span id="clock"></span></CENTER><BR>
[COLOR="red"]onLoad="showdate()"[/COLOR]
onload="showdate()" should be inside an element. Try:
Code:
<CENTER><span id="clock" onLoad="showdate()"></span></CENTER><BR>
 
But i did close the head and the body was also opened and closed, where actually are you referring to?

Yes you did close them, but you did it wrong. You closed the body, then the head. So in short you placed the body in the head. That is wrong.

Basic HTML 101 template:
Code:
<html>
<head><title> TITLE </title></head>
<body> CONTENT </body>
</html>
 
Top
Sign up to the MyBroadband newsletter
X