PcolaSteve
Programmer
I have a site that is requiring the current date and time to be shown in a particular <div>. I have the day and date showing properly but cannot seem to get the time to position where it needs to be positioned. Here is the JS that is in the <head> tag.
<script type="text/javascript">
function startTime()
{ //start function startTime
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
//add a 0 in front of numbers < 10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('startTime()',500);
} //end fuction startTime
function checkTime(i)
{ //start function checkTime
if(i<10)
{
i="0" + i;
}
return i;
}
</script>
Here is the opening <body> tag:
<body onload="startTime() "style="background-image: url('images/bg.gif'); background-repeat: repeat-x; margin-top: 12px;">
If I follow the above tag with <div id="txt"></div> it will show but not where I need it. Here is where it needs to appear.
<div id="dateTime" style="position: relative; width: 742px; height: 20px; z-index: 4; float: left; padding-top: 3px; padding-left: 3px; border-bottom-style: solid; border-bottom-width: thin;">
<script type="text/javascript">document.write("Today is " + weekday[d.getDay()] + " " + (MON)+ " " + (dd)+ ", " + (today)+ ". The time is: "THIS IS WHERE THE TIME NEEDS TO APPEAR!)</script>
</div>
Any suggestions?
The shortest distance between two points is NOT a straight line; it's through a worm hole!
<script type="text/javascript">
function startTime()
{ //start function startTime
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
//add a 0 in front of numbers < 10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('startTime()',500);
} //end fuction startTime
function checkTime(i)
{ //start function checkTime
if(i<10)
{
i="0" + i;
}
return i;
}
</script>
Here is the opening <body> tag:
<body onload="startTime() "style="background-image: url('images/bg.gif'); background-repeat: repeat-x; margin-top: 12px;">
If I follow the above tag with <div id="txt"></div> it will show but not where I need it. Here is where it needs to appear.
<div id="dateTime" style="position: relative; width: 742px; height: 20px; z-index: 4; float: left; padding-top: 3px; padding-left: 3px; border-bottom-style: solid; border-bottom-width: thin;">
<script type="text/javascript">document.write("Today is " + weekday[d.getDay()] + " " + (MON)+ " " + (dd)+ ", " + (today)+ ". The time is: "THIS IS WHERE THE TIME NEEDS TO APPEAR!)</script>
</div>
Any suggestions?
The shortest distance between two points is NOT a straight line; it's through a worm hole!