...

View Full Version : dynamic clock



josh81790
08-10-2004, 02:20 AM
I made a dynamic clock but it only works inside a textbox.

<html>
<body>The Time Is<form name="myclock">
<input type="text" name="thebox" size="40" maxlength="256">

</form></body><head><script type="text/javascript">
function joshfunction(){
var joshdate=new Date()
hour=joshdate.getHours()
minutes=joshdate.getMinutes()
seconds=joshdate.getSeconds()
var hello

if((hour>12)){
hour=hour-12
hello="P.M."
}
else
{
hello="A.M."
}
if((hour==0))hour=12
if((minutes<9))minutes="0"+minutes
if((seconds<9))seconds="0"+seconds

document.myclock.thebox.value=(hour+":"+minutes+" and "+seconds+' seconds '+hello)
}
</script></head><body onLoad="setInterval('joshfunction()',1000)"></body></html>




How can i make that clock update using css without it being in a textbox? :confused:

Willy Duitt
08-10-2004, 03:04 AM
Use a span and innerHTML instead of the form...

Without changing to much of your code, other than what was necassary and/or removing completely redundant variables...


<html>
<script type="text/javascript">
function joshfunction(){
var hours = new Date().getHours();
var minutes = new Date().getMinutes();
var seconds = new Date().getSeconds();

if(hours > 12){
hours = hours-12;
var hello = 'P.M.';
} else{ var hello = 'A.M.' };

if(hours == 0)hours = 12;
if(minutes <= 9)minutes = '0'+minutes;
if(seconds <= 9)seconds = '0'+seconds;

document.getElementById('myclock').innerHTML = hours+":"+minutes+" and "+seconds+' seconds '+hello;
setTimeout('joshfunction()',1000);
}
</script>
</head>

<body onLoad="joshfunction()">
The Time Is: <span id="myclock"></span>
</body>
</html>


.......Willy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum