Forum Moderators: open
It seems logical to me (as a beginning js writer) to call the function in an onload event, but it doesn't work.
Can someone tell me how to do this properly. It seems to be the only error in the code thus far.
I have to keep the code itself intact as it's a tech project.
thanks if u can help.....antipodes
<html>
<head>
<script Language="JavaScript">
<!-- hide
var timeStr, dateStr;
function clock() {
now= new Date();
// time
hours= now.getHours();
minutes= now.getMinutes();
seconds= now.getSeconds();
timeStr= "" + hours;
timeStr+= ((minutes < 10)? ":0" : ":") + minutes;
timeStr+= ((seconds < 10)? ":0" : ":") + seconds;
document.clock.time.value = timeStr;
// date
date= now.getDate();
month= now.getMonth()+1;
year= now.getYear();
dateStr= "" + month;
dateStr+= ((date < 10)? "/0" : "/") + date;
dateStr+= "/" + year;
document.clock.date.value = dateStr;
Timer= setTimeout("clock()",1000);
}
// -->
</script>
<script type="text/javascript" language="JavaScript">
<!--start hiding
function newWindow() {
var url="";
var name="popup";
var features="width=190,height=200,menubar=yes,status=yes";
myNewWindow=window.open(url,name,features);
myNewWindow.focus();
//give the new window focus
myNewWindow.document.open();
//open a document
myNewWindow.document.write("<html>");
myNewWindow.document.write("<head>");
myNewWindow.document.write("<title>Clock Displayer</title>");
myNewWindow.document.write("</head>");
myNewWindow.document.write("<body onLoad='clock()'>")
myNewWindow.document.write("<form name='display'>");
myNewWindow.document.write("<p>Time:</p>");
myNewWindow.document.write("<input type='text' name='time' size='16' value=''><br>");
myNewWindow.document.write("<p>Date:</p>");
myNewWindow.document.write("<input type='text' name='date' size='16' value=''>");
myNewWindow.document.write("</form>");
myNewWindow.document.write("<div align='right'>");
myNewWindow.document.write("<input type='button' value='EXIT' onClick='parent.close()'><br>");
myNewWindow.document.write("</div>");
myNewWindow.document.write("</body>");
myNewWindow.document.write("</html>");
myNewWindow.document.close();
}
//-->
</script>
</head>
<body bgcolor="#cccc99" text="#330000" link="navy" vlink="navy">
<h4>Topic 9<br>JavaScript ~ date object.</h4>
<hr color=#003300 noshade size=2>
<br>
<a href="JavaScript:newWindow('url','name','features')">Open Clock</A>
<br><br><br>
<hr color=#003300 noshade size=2>
</body>
</html>
</body>
</html>
function clock() {
now= new Date();
// time
hours= now.getHours();
minutes= now.getMinutes();
seconds= now.getSeconds();
timeStr= "" + hours;
timeStr+= ((minutes < 10)? ":0" : ":") + minutes;
timeStr+= ((seconds < 10)? ":0" : ":") + seconds;
popup.document.display.time.value = timeStr;
// date
date= now.getDate();
month= now.getMonth()+1;
year= now.getYear();
dateStr= "" + month;
dateStr+= ((date < 10)? "/0" : "/") + date;
dateStr+= "/" + year;
popup.document.display.date.value = dateStr;
Timer= setTimeout("clock()",1000);
}