Purple Martin

msg:1483813 | 6:03 am on Sep 11, 2002 (gmt 0) |
You could do the following: 1. Put a span (with id) in the document where you want something displayed (instead of using a script tag). 2. Write a JavaScript function which changes the innerHTML property of the span to what you want displayed. 3. Make the function call itself every 10 seconds using setTimeout. 4. Call the function with the body onLoad event to get it started. HTH
|
keyplyr

msg:1483814 | 6:21 am on Sep 11, 2002 (gmt 0) |
Thanks Purple_Martin but #2, #3 and #4 are over my head - LOL Regardless, I was hoping there was just an element to add to the JS string.
|
Purple Martin

msg:1483815 | 6:50 am on Sep 11, 2002 (gmt 0) |
lol, OK, I'll give more info then! There is nothing you can just add to the code snippet you've got. Once it has s written it's stuff to the document, it's done it's job and that's it. Game over. So here is some sample code to look at for each of the 4 steps (I'm just typing it straight in without testing so apolgies if I give you errors). 1: <span id="mySpan"></span> 2 & 3 (put in the head): <script language="javascript"> function changeMySpan() { var myDate = "" + new Date(yyyy,mm,dd,hh,mm,ss) // change the format as you like document.all["mySpan"].innerHTML = myDate setTimeout("changeMySpan()", 10000) // the number is the delay in milliseconds } </script> 4: <body onLoad="changeMySpan()"> Of course the document.all part won't work in Netscape, so doe a search for browser sniffing scripts and "getElementById" for info about accessing an element's properties in Netscape.
|
keyplyr

msg:1483816 | 8:12 am on Sep 11, 2002 (gmt 0) |
Thanks again, I'll play around with it.
|
rewboss

msg:1483817 | 9:39 am on Sep 11, 2002 (gmt 0) |
An alternative is to leave out the setTimeout method in the function body, and change the onload handler to: onload="setInterval('changeMySpan()', 10000);" It's slightly more efficient than using setTimeout to recursively call a function. Well, not so's you'd notice, but it is a bit more elegant.
|
|