Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2004, 04:50 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reload Image and Date - Time

I am using a javascript function to reload an image on a webpage. Now I would also like to reload the date and time at the same time.

How can this be done? I would really like to be able to display the date and time over the bottom of the image. Can anyone help?

The script I am using is given below.

Freddo

<img src="cam.jpg" alt="Local Weather" name="image1">

 <script language="JavaScript" type="text/javascript">
<!--
interval = 5000;
imgsrc = "cam.jpg";

function Refresh() {
   tmp = new Date();
   tmp = "?" + tmp.getTime();
   document.images["image1"].src = imgsrc + tmp;
   setTimeout("Refresh()", interval);
}

Refresh();

-->
</script>
 
Old August 29th, 2004, 05:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

Your best bet is to use a DIV and then use DHTML to update the contents of that DIV, see the http://www.greggriffiths.org/ for a sample on the main page.
 
Old August 29th, 2004, 05:17 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply Greg. I looked at your homepage link but cannot see how that helps!

Joe999

 
Old September 2nd, 2004, 10:15 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Freddo,

How about this?

<html>
<head>
</head>
<body onload ="getNew()">
<P Id ="P1"><img src="cam.gif"></P>
<script language="JavaScript">
function getNew(){

var tmp = new Date(); //get system date
var thisHour = tmp.getHours();//get hours from system date

var thisMin = tmp.getMinutes();//get minutes from system date
if(thisMin < 10){
thisMin = "0" + thisMin;
}

var thisSec = tmp.getSeconds();//get seconds from system date
if (thisSec < 10){
thisSec = "0" + thisSec
}

window.status = "Time: " + thisHour + ":" + thisMin + ":" + thisSec
//I stuffed the time in the status bar, cos it always looks better
P1.innerHTML = "<img src \"cam.gif\">"
window.setTimeout("getNew()", 5000);
                }
</script>

</body>
</html>

I also chucked in some if statements to pad out minutes and seconds with zeros if they were at less than ten.

HTH
interrupt

 
Old September 2nd, 2004, 10:08 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi interrupt - thanks for that. I give it a try

Freddo




Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting Time from Date/Time Navy1991_1 XSLT 2 June 3rd, 2008 12:03 PM
date and time in EST time zone anboss XSLT 1 May 21st, 2008 01:42 PM
Reload page Tooltip not work - Reload xslt file? ismailc XSLT 10 January 22nd, 2008 10:03 AM
Page reload when image changed in server rads J2EE 0 January 17th, 2006 10:30 PM
insert system date. no date and time jimmy Access VBA 6 November 20th, 2003 01:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.