Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Positioning Question

Status
Not open for further replies.

PcolaSteve

Programmer
Jul 1, 2011
30
US
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!
 
I may be missing something, but can't you just change the ID of the element who's content your are changing to the one you want?

Code:
document.getElementById('[red]dateTime[/red]').innerHTML=h+":"+m+":"+s;

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Not sure because it is strictly a positioning issue but I will give it a try. Thanks!

The shortest distance between two points is NOT a straight line; it's through a worm hole!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top