Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-25-2002, 02:05 AM   PM User | #1
Hawk
New Coder

 
Join Date: Jul 2002
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Hawk is an unknown quantity at this point
Write Time

How can you write the time every second. I am using document.write but it wipes out the previous time. I want as each second pass, the next time will be on the next line.

Thanks

I don't know what to search on this one.
Hawk is offline   Reply With Quote
Old 07-25-2002, 02:37 AM   PM User | #2
Astro-Boy
New Coder

 
Join Date: Jun 2002
Location: Sydney, NSW, Australia
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Astro-Boy is an unknown quantity at this point
The easiest way would be to update a form element every second, otherwise you'll need to use dynamic layers.

Alternatively you could download a pre-made time script from javascriptkit or dynamicdrive.

- Mark
__________________
[ AstroBoy Online | Experiments in Stuff | Google, use it! ]
Astro-Boy is offline   Reply With Quote
Old 07-25-2002, 12:58 PM   PM User | #3
nolachrymose
Regular Coder

 
Join Date: Jun 2002
Posts: 338
Thanks: 0
Thanked 0 Times in 0 Posts
nolachrymose is an unknown quantity at this point
Code:
<div id="clock">8:88</div>
<script type="text/javascript">
var clk=document.getElementById("clock").firstChild;

function time() {
var minutes=new Date().getMinutes();
var hours=new Date().getHours();
var seconds=new Date().getSeconds();
if(hours<12) hours-=12;

clk.nodeValue=hours+":"+minutes+:":"+seconds;
setTimeout(time,1000);
} time();
</script>
nolachrymose is offline   Reply With Quote
Old 07-25-2002, 02:05 PM   PM User | #4
JoeP
Regular Coder

 
Join Date: Jun 2002
Location: Plano, Texas
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
JoeP is an unknown quantity at this point
I gave a sample script that does just that on a previous post. Refer to:

http://www.codingforums.com/showthre...?threadid=2551
JoeP is offline   Reply With Quote
Old 07-25-2002, 05:36 PM   PM User | #5
Hawk
New Coder

 
Join Date: Jul 2002
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Hawk is an unknown quantity at this point
Thumbs up Thanks for your replies!!!

nolachrymose, your script gave me an error.


JoeP, does your script keep the previous content? I was looking for something that writes the new time out on a new line every second. It will keep the previous content.

Mark, I will look into that.
Hawk is offline   Reply With Quote
Old 07-25-2002, 07:04 PM   PM User | #6
Hawk
New Coder

 
Join Date: Jul 2002
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Hawk is an unknown quantity at this point
Something like this!

I just can't get the scroll to work but something like this.

Code:
		<script language="JavaScript">
			var T = window.open("",'Window_ID','menubar=no,status=no,location=no,toolbar=no,scrollbars=yes,resizable=no');
			T.resizeTo(200,200);
			T.moveTo((screen.width - 200)/2,(screen.height - 200)/2);

			var timerID = null
			var	timerRunning = false
			function stopclock()
			{
				if(timerRunning)
					clearInterval(timerID)
					timerRunning = false
			}
			function startclock()
			{
				// Make sure the clock is stopped
				stopclock()
				timerID = window.setInterval("showtime()",1000)
				timerRunning = true
			}
			function showtime()
			{
				var now = new Date()
				var hours = now.getHours()
				var minutes = now.getMinutes()
				var seconds = now.getSeconds()
				var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
				timeValue += ((minutes < 10) ? ":0" : ":") + minutes
				timeValue += ((seconds < 10) ? ":0" : ":") + seconds
				timeValue += (hours >= 12) ? " P.M." : " A.M."
				//top.Right_Area.document.writeln(timeValue + '<br>');

				if (T.closed)
				{
					clearInterval(timerID);
				}
				else
				{
					T.document.writeln(timeValue + '<br>');
					//T.scrollBy(0, 30);
					T.focus();
				}
			}
		</script>
Hawk is offline   Reply With Quote
Old 02-28-2004, 05:13 PM   PM User | #7
oldcrazylegs
Regular Coder

 
oldcrazylegs's Avatar
 
Join Date: Feb 2004
Location: East Moline Illinois USA
Posts: 412
Thanks: 2
Thanked 5 Times in 4 Posts
oldcrazylegs is an unknown quantity at this point
document.write the easy way

http://javascript.about.com/library/...ldocwriter.htm
oldcrazylegs is offline   Reply With Quote
Old 02-28-2004, 05:31 PM   PM User | #8
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
Could you please tell me what is the point in bringing posts TTT which were resolved over six monthes ago?

.....Willy
Willy Duitt is offline   Reply With Quote
Old 02-28-2004, 06:02 PM   PM User | #9
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
Look at the date again... over 1 year and 6 months
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:48 AM.


Advertisement
Log in to turn off these ads.