473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Timer on webpages

Hi,

Im not sure where to find all the documentation i need for this? I need
to timer since a start button has been pushed, and show a counter on a
page. If they click stop i want to keep the time, and carry on
incrementing it if they click start again.

Any suggestions on code, or reference material for this?

Thanks for all the help

David

Apr 29 '06 #1
13 1464
On 2006-04-29, David <da************@gmail.com> wrote:
Hi,

Im not sure where to find all the documentation i need for this? I need
to timer since a start button has been pushed, and show a counter on a
page. If they click stop i want to keep the time, and carry on
incrementing it if they click start again.

Any suggestions on code, or reference material for this?


Tricky one. I can't think of a way except using setInterval, with an
interval of about a second. In the callback you update the counter,
animation, etc., and increment a variable that counts how many seconds have
elapsed.
Apr 29 '06 #2
Ben C said the following on 4/29/2006 11:53 AM:
On 2006-04-29, David <da************@gmail.com> wrote:
Hi,

Im not sure where to find all the documentation i need for this? I need
to timer since a start button has been pushed, and show a counter on a
page. If they click stop i want to keep the time, and carry on
incrementing it if they click start again.

Any suggestions on code, or reference material for this?
Tricky one.


Not really.
I can't think of a way except using setInterval,
There are other ways but setInterval would be the best way to update the
page itself. Not necessarily the best way to increment the counter though.
with an interval of about a second.
The resolution you used for setInterval would depend on how much
resource you would be willing to use and how accurate you wanted the
counter time wise.
In the callback you update the counter, animation, etc.,
and increment a variable that counts how many seconds have elapsed.


I don't agree with that one. Incrementing a variable would lead to
inaccuracies in the total. Just start with a Date object and compare the
current time, get the difference, and display it.

The only difference in this question and any other "running counter"
question is the Start/Stop buttons. And how you handled those would
depend, directly, on whether the OP wanted the timer to include the
Stopped time or not.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 29 '06 #3
JRS: In article <mM******************************@comcast.com>, dated
Sat, 29 Apr 2006 14:34:28 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
In the callback you update the counter, animation, etc.,
and increment a variable that counts how many seconds have elapsed.


I don't agree with that one. Incrementing a variable would lead to
inaccuracies in the total. Just start with a Date object and compare the
current time, get the difference, and display it.


Using a Date Object to indicate duration will be unreliable in systems
where the clock is being automatically synchronised from time to time.

Using a Date Object naively to indicate duration will be unreliable when
the season changes between Summer and Winter.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Apr 29 '06 #4
Dr John Stockton said the following on 4/29/2006 5:25 PM:
JRS: In article <mM******************************@comcast.com>, dated
Sat, 29 Apr 2006 14:34:28 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
In the callback you update the counter, animation, etc.,
and increment a variable that counts how many seconds have elapsed. I don't agree with that one. Incrementing a variable would lead to
inaccuracies in the total. Just start with a Date object and compare the
current time, get the difference, and display it.


Using a Date Object to indicate duration will be unreliable in systems
where the clock is being automatically synchronised from time to time.


If your app is that time critical, then you would know whether that was
happening or not and if you didn't allow for it then you get what you
deserve.
Using a Date Object naively to indicate duration will be unreliable when
the season changes between Summer and Winter.


And naively assuming that most business applications are being used on a
Saturday night at 2AM is indeed naive.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 30 '06 #5
Randy Webb wrote:
Dr John Stockton said the following on 4/29/2006 5:25 PM:
JRS: In article <mM******************************@comcast.com>, dated
Sat, 29 Apr 2006 14:34:28 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
In the callback you update the counter, animation, etc., and
increment a variable that counts how many seconds have elapsed.
I don't agree with that one. Incrementing a variable would lead to
inaccuracies in the total. Just start with a Date object and compare
the current time, get the difference, and display it.


Using a Date Object to indicate duration will be unreliable in systems
where the clock is being automatically synchronised from time to time.


If your app is that time critical, then you would know whether that was
happening or not and if you didn't allow for it then you get what you
deserve.


Absolutely, so worth mentioning.

Using a Date Object naively to indicate duration will be unreliable when
the season changes between Summer and Winter.


And naively assuming that most business applications are being used on a
Saturday night at 2AM is indeed naive.


That is not naive at all - many businesses that have a production
process have shift work. I've frequently been involved in projects with
24hr shifts, 7 days per week over many months. That is common on
projects such as those that use very expensive CAD equipment, say a
major construction project.
--
Rob
Apr 30 '06 #6
RobG said the following on 4/29/2006 10:54 PM:
Randy Webb wrote:
Dr John Stockton said the following on 4/29/2006 5:25 PM:
JRS: In article <mM******************************@comcast.com>, dated
Sat, 29 Apr 2006 14:34:28 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
> In the callback you update the counter, animation, etc., and
> increment a variable that counts how many seconds have elapsed.
I don't agree with that one. Incrementing a variable would lead to
inaccuracies in the total. Just start with a Date object and compare
the current time, get the difference, and display it.

Using a Date Object to indicate duration will be unreliable in systems
where the clock is being automatically synchronised from time to time.


If your app is that time critical, then you would know whether that
was happening or not and if you didn't allow for it then you get what
you deserve.


Absolutely, so worth mentioning.

Using a Date Object naively to indicate duration will be unreliable when
the season changes between Summer and Winter.


And naively assuming that most business applications are being used on
a Saturday night at 2AM is indeed naive.


That is not naive at all - many businesses that have a production
process have shift work. I've frequently been involved in projects with
24hr shifts, 7 days per week over many months. That is common on
projects such as those that use very expensive CAD equipment, say a
major construction project.


True, but that falls into the first category. That is a time critical
application and if you don't take care to account for it then you, well,
deserve what you get :)

But, your point is valid.

But, most sites that have a count-down/up timer are not business apps.
Some are, but most aren't. Probably a quiz type site that the OP has.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 30 '06 #7
JRS: In article <EN******************************@comcast.com>, dated
Sat, 29 Apr 2006 20:56:16 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
Dr John Stockton said the following on 4/29/2006 5:25 PM:

Using a Date Object naively to indicate duration will be unreliable when
the season changes between Summer and Winter.


And naively assuming that most business applications are being used on a
Saturday night at 2AM is indeed naive.


It would be; but we should not be concerned just with "most" here; and
it is naive to assume that the clock necessarily changes at 2AM.

Then just consider all the Muslim and Jewish businessmen; the businesses
that run 24/7/366; the travellers who keep there portables set to Home
Time, ...

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Apr 30 '06 #8
Dr John Stockton said the following on 4/30/2006 5:50 PM:
JRS: In article <EN******************************@comcast.com>, dated
Sat, 29 Apr 2006 20:56:16 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
Dr John Stockton said the following on 4/29/2006 5:25 PM:
Using a Date Object naively to indicate duration will be unreliable when
the season changes between Summer and Winter.

And naively assuming that most business applications are being used on a
Saturday night at 2AM is indeed naive.


It would be; but we should not be concerned just with "most" here; and
it is naive to assume that the clock necessarily changes at 2AM.


And this entire scenario falls into the part of my reply that you snipped:

<quote>
If your app is that time critical, then you would know whether that was
happening or not and if you didn't allow for it then you get what you
deserve.
</quote>
Then just consider all the Muslim and Jewish businessmen; the businesses
that run 24/7/366; the travellers who keep there portables set to Home
Time, ...


I am not sure what being Muslim or Jewish has to do with that.

But, it still falls into the first category.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 1 '06 #9
JRS: In article <O6******************************@comcast.com>, dated
Sun, 30 Apr 2006 22:37:29 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
Dr John Stockton said the following on 4/30/2006 5:50 PM:
JRS: In article <EN******************************@comcast.com>, dated
Sat, 29 Apr 2006 20:56:16 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
Dr John Stockton said the following on 4/29/2006 5:25 PM:

Using a Date Object naively to indicate duration will be unreliable when
the season changes between Summer and Winter.
And naively assuming that most business applications are being used on a
Saturday night at 2AM is indeed naive.


It would be; but we should not be concerned just with "most" here; and
it is naive to assume that the clock necessarily changes at 2AM.


And this entire scenario falls into the part of my reply that you snipped:

<quote>
If your app is that time critical, then you would know whether that was
happening or not and if you didn't allow for it then you get what you
deserve.
</quote>


Don't assume that questioners and readers are as intelligent as you
think you are.
Then just consider all the Muslim and Jewish businessmen; the businesses
that run 24/7/366; the travellers who keep there portables set to Home
Time, ...


I am not sure what being Muslim or Jewish has to do with that.


Knowing nothing about other cultures is part of being a WASP, no doubt.
FYI, those people do not regard Sunday as the ordained Day of Rest.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
May 1 '06 #10
David wrote:
Im not sure where to find all the documentation i need for this? I need
to timer since a start button has been pushed, and show a counter on a
page. If they click stop i want to keep the time, and carry on
incrementing it if they click start again.


<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css" media="all">
.clock {
text-align:center;
font-family: Courier, Courier New;
font-size: 30px;
font-weight: bold;
background-color: white;
border: 0px;
border-style: solid;
border-color: white;
}

body {
background-color: white;
}
</style>
<script language="javascript" type="text/javascript">

// 1000 = 1 second.
// A reliable 'real seconds' timer is only 1000 (or above)
// on nowadays machines, because CPU will slowdown the
// timer if it are small intervals.
// The lower the value, the longer your 'seconds' will become.
// If the real time is not important for you (you wrote about
// 'a counter'), you can set this value as low as you like.
var interval = 1000;

// These should be left as they are
var tijdID = null;
var tijdLoopt = false;

function stop_klok() {
if (tijdLoopt)
clearTimeout(tijdID);
tijdLoopt = false;
}

function toon_tijd() {
var now = new Date();
seconden = parseFloat(document.counterform.cf.value);
seconden = seconden + 1;
huidigeTijd = '';
if (seconden < 10)
huidigeTijd='00000'+seconden;
if (seconden < 100 && seconden >= 10)
huidigeTijd='0000'+seconden;
if (seconden < 1000 && seconden >= 100)
huidigeTijd='000'+seconden;
if (seconden < 10000 && seconden >= 1000)
huidigeTijd='00'+seconden;
if (seconden < 100000 && seconden >= 10000)
huidigeTijd='0'+seconden;
document.counterform.cf.value = huidigeTijd;
tijdID = setTimeout("toon_tijd()", interval);
tijdLoopt=true;
}

function start_klok() {
stop_klok();
toon_tijd();
}
</script>
</head>

<body>

<form name="counterform">
<center>
<input onFocus="blur();" type="text" name="cf"
size="13" class="clock" value="000000">
<br/>
<input type="button" value="Start" onClick="start_klok();">
<input type="button" value="Stop" onClick="stop_klok();">

</center>
</form>

</body>
</html>

--
Bart

May 2 '06 #11
Bart Van der Donck wrote:
[...]
var now = new Date();
[...]


No need for that line.

--
Bart

May 2 '06 #12
Dr John Stockton said the following on 5/1/2006 2:11 PM:
JRS: In article <O6******************************@comcast.com>, dated
Sun, 30 Apr 2006 22:37:29 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
Dr John Stockton said the following on 4/30/2006 5:50 PM:
JRS: In article <EN******************************@comcast.com>, dated
Sat, 29 Apr 2006 20:56:16 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
Dr John Stockton said the following on 4/29/2006 5:25 PM:
> Using a Date Object naively to indicate duration will be unreliable when
> the season changes between Summer and Winter.
And naively assuming that most business applications are being used on a
Saturday night at 2AM is indeed naive.
It would be; but we should not be concerned just with "most" here; and
it is naive to assume that the clock necessarily changes at 2AM. And this entire scenario falls into the part of my reply that you snipped:

<quote>
If your app is that time critical, then you would know whether that was
happening or not and if you didn't allow for it then you get what you
deserve.
</quote>


Don't assume that questioners and readers are as intelligent as you
think you are.


Coming from someone that is as pedantic as you are, that doesn't bother
me. Try harder.
Then just consider all the Muslim and Jewish businessmen; the businesses
that run 24/7/366; the travellers who keep there portables set to Home
Time, ...

I am not sure what being Muslim or Jewish has to do with that.


Knowing nothing about other cultures is part of being a WASP, no doubt.


Muslim and Jewish is not a "culture", it is a religion. The culture you
are referring to would be Arab (Muslim) and Israeli (Jewish). Practice
what you preach. And, for someone who composes off-line and then posts,
you seem to be pretty lazy and overly fond of unknown acronyms.
FYI, those people do not regard Sunday as the ordained Day of Rest.


Your mastery of the obvious is starting to approach that of TL. Having
lived in an Arab culture for about 2 years, I am well aware of the Holy
Day (It is not an "ordained Day of Rest" to Muslims, it is the Holy Day)
being on Friday (In both cultures). Still, it has nothing to do with
time changing at 2AM in Daylight Savings Time (where practiced).

As in the past, I have told you, stick to Dates and Times, you suck at
common sense John.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 2 '06 #13
JRS: In article <11**********************@v46g2000cwv.googlegroups .com>
, dated Tue, 2 May 2006 02:35:36 remote, seen in
news:comp.lang.javascript, Bart Van der Donck <ba**@nijlen.com> posted :
var interval = 1000; function toon_tijd() {
var now = new Date();
seconden = parseFloat(document.counterform.cf.value);
seconden = seconden + 1;
Maybe seconden = +document.counterform.cf.value + 1
huidigeTijd = '';
if (seconden < 10)
huidigeTijd='00000'+seconden;
if (seconden < 100 && seconden >= 10)
huidigeTijd='0000'+seconden;
if (seconden < 1000 && seconden >= 100)
huidigeTijd='000'+seconden;
if (seconden < 10000 && seconden >= 1000)
huidigeTijd='00'+seconden;
if (seconden < 100000 && seconden >= 10000)
huidigeTijd='0'+seconden;
document.counterform.cf.value = huidigeTijd;
tijdID = setTimeout("toon_tijd()", interval);
tijdLoopt=true;
}


It is perhaps better not to use seconden as the name of what is
counted in a VAR interval; I'd use Ticks to be more general, or hard-
code 1000 throughout.

In at least some systems, repeating setTimeout(..., 1000) gives an
average interval of longer than a second, because of overheads and
waiting for the next check. See <URL:http://www.merlyn.demon.co.uk/js-
date0.htm#TaI>.

Consider whether the computer's clock may be adjusted during the
interval, and whether it will matter.

By using new Date() results at the beginning and end of the interval,
you can check your counting (if the clock is not adjusted).

Consider huidigeTijd = String(1e6+seconden).substring(1)
and
huidigeTijd = seconden + ""
while (huidigeTijd.length<6) huidigeTijd = "0" + huidigeTijd

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
May 2 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
2
by: DaveF | last post by:
I am trying to write a service to fire an ftp object off. I want to wait 2 minutes and then download the files. Then repeat every 2 minutes. The files just seem to stop downloading. Does that timer...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
3
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
2
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: ...
12
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different...
8
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
I have a Timer that I set to go off once a day, but it frequently fails! In order to debug I would like to be able to check, at any moment, whether the Timer is enabled and when it will next...
16
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.