help finding this

B

Bob

Hello,

I am not a js programmer, but i was hoping to find a prewritten script
that i may be able to use. all i need is a simple count up timer that
has a start, pause, and stop control to it, i have found some, but they
all seem to reset once you pause them, and i need it to stay where it
is at and then continue from the paused point once someone hits
restart.

if anyone knows where i can find something like this i would appreciate
it.

Thank you
 
B

Bart Van der Donck

Bob said:
I am not a js programmer, but i was hoping to find a prewritten script
that i may be able to use. all i need is a simple count up timer that
has a start, pause, and stop control to it, i have found some, but they
all seem to reset once you pause them, and i need it to stay where it
is at and then continue from the paused point once someone hits
restart.

<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
i = 50 // bigger = slower, smaller = faster
tR = false
function sTime() {
++ document.c.cf.value
T = setTimeout('sTime()', i)
tR=true;
}
function cTime(arg) {
if (tR) clearTimeout(T)
tR = false
if (arg == 1) sTime()
if (arg == 3) document.c.cf.value = 0
}
</script>
</head>

<body>
<form name="c">
<input type="text" name="cf" value="0">
<input type="button" value="Start" onClick="cTime(1)">
<input type="button" value="Pause" onClick="cTime(2)">
<input type="button" value="Reset" onClick="cTime(3)">
</form>
</body>
</html>

Hope this helps,
 
R

RobG

Bob said:
Hello,

I am not a js programmer, but i was hoping to find a prewritten script
that i may be able to use. all i need is a simple count up timer that
has a start, pause, and stop control to it, i have found some, but they
all seem to reset once you pause them, and i need it to stay where it
is at and then continue from the paused point once someone hits
restart.

If you want a counter that resonably accurately counts seconds, you
need to use a date object and run the counter every 50ms or so to grab
the system time and use that to count in roughly equal seconds.

If you just want a counter that runs about every 100ms or so and time
accuracy is not important, then the script below will do the job.


<script type="text/javascript">

var pageCounter = (function()
{
var counterLag = 100; // Milliseconds between updates
var counterValue = 0; // Initial value
var counterRef; // Reference to current timer
var textElement; // Element to displaying value

return {

// Initialise values and start the timer if one isn't
// running already. Don't zero the counter
start : function(id)
{
if (!document.getElementById) return;
textElement = document.getElementById(id);
if (!textElement) return;
if (!counterRef) pageCounter.run();
},

// Run the counter - uses setTimeout to call itself
// reasonably regularly and update the counter.
run : function()
{
textElement.innerHTML = counterValue++;
counterRef = setTimeout('pageCounter.run()', counterLag);
},

// Stop the counter but don't zero the counter
stop : function()
{
if (counterRef) clearTimeout(counterRef);
counterRef = null;
},

// Stop and zero the counter
clear : function()
{
if (counterRef) pageCounter.stop();
counterValue = 0;
textElement.innerHTML = counterValue;
}
}
})();

</script>

<button onclick="pageCounter.start('xx')">Start</button>
<button onclick="pageCounter.stop()">Stop</button>
<button onclick="pageCounter.clear()">Clear</button>

<br><span id="xx"></span>
 
B

Bob

yeah, i need to have something that is pretty accurate, i need it to be
within a second or 2 after a 3 minute period.

another question: if i were to use it as a countDOWN, would this be
more accurate?

once again, thank you.
 
B

Bart Van der Donck

Bob said:
yeah, i need to have something that is pretty accurate, i need it to be
within a second or 2 after a 3 minute period.

Well, RobG's 'counterLag'- and my 'i'-variable are actually the number
of milliseconds between each value change. Setting it to 1000 would be
the best option to approach a real second (but you can't trust that you
will have an accurate second here).
another question: if i were to use it as a countDOWN, would this be
more accurate?

That would make no difference as it depends on the same timer mechanism
anyhow.
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Mon, 7 Aug 2006 21:08:27 remote, seen in
news:comp.lang.javascript said:
Bob wrote:

Therefore you should read the newsgroup FAQ before posting.
You should also give an informative Subject line.

If you want a counter that resonably accurately counts seconds, you
need to use a date object

Yes; or to be more exact a succession of such. It seems a pity that
there's no way of getting the date/time directly into an existing Date
Object - a .refresh() method is missing.
and run the counter every 50ms or so to grab
the system time and use that to count in roughly equal seconds.

No need to call the system time more often than it will be used, unless
the interval is to be long. See in <URL:http://www.merlyn.demon.co.uk/
js-date2.htm>.

The following, simplified therefrom, will lock its count to the seconds
of the computer - note the last line of code :-

function Kount() { // var Kounter will be global
DynWrite("Down", ++Kounter)
setTimeout("Kount()", 1050-new Date()%1000) }

Or see <URL:http://www.merlyn.demon.co.uk/js-date0.htm#TaI>, function
Tock, contrasted with Tick.
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Tue, 8 Aug 2006 08:52:59 remote, seen in
news:comp.lang.javascript said:
Well, RobG's 'counterLag'- and my 'i'-variable are actually the number
of milliseconds between each value change. Setting it to 1000 would be
the best option to approach a real second (but you can't trust that you
will have an accurate second here).

In *at least* some browsers, you can trust that you will not have an
accurate second, even on average.

Read the newsgroup FAQ.
 
B

Bob

ok, please allow me to rephrase to explain better,

i am not an EXPERIENCED js programmer, i am learning as i go, i read
the faq, however i thought this was a "HELP" forum, and i needed help.

I thank you to those that helped me, i have a better understanding now
of time counts on js and with what you have supplied i have solved the
problem.

Once again, thank you..
 
R

Randy Webb

Bob said the following on 8/9/2006 11:59 AM:
ok, please allow me to rephrase to explain better,

Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
i am not an EXPERIENCED js programmer, i am learning as i go, i read
the faq, however i thought this was a "HELP" forum, and i needed help.

No, it is not a "help forum", it is a Usenet Discussion Group. You post,
it gets discussed. Nothing more, nothing less.
 
B

Bob

wow randy,

you need to get a life.. you have nothing better to do than to go
around and nitpick on "discussion forums" when someone asks a
question??

seriously, put down your mouse and your pocket protector, open up you
front door, you know, the big rectangle thing in the front of your
house, step through it and take a deep breath. then once you have
hopefully refreshed and realized that life is out there waiting for
you, you can come back here and not be such a sphincter muscle.

my 2 cents....
 
E

Evertjan.

Bob wrote on 09 aug 2006 in comp.lang.javascript:
Randy said:
Bob said the following on 8/9/2006 11:59 AM: [...]

Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
[...]
read the faq, however i thought this was a "HELP" forum, and i
needed help.

No, it is not a "help forum", it is a Usenet Discussion Group. You
post, it gets discussed. Nothing more, nothing less.

[please do not toppost on usenet, especially when asked not to do that]

[...]
you need to get a life.. you have nothing better to do than to go
around and nitpick on "discussion forums" when someone asks a
question??

seriously, put down your mouse and your pocket protector, open up you
[...]

Are we touchy today?

Randy is completly right on both accounts.

This is not a help forum. And topposting is inferior to sparse
interposting, as shown in the example.
 
R

Randy Webb

Bob said the following on 8/9/2006 2:15 PM:
wow randy,

you need to get a life.. you have nothing better to do than to go
around and nitpick on "discussion forums" when someone asks a
question??

No thanks, I already have a life, a happy one at that. And when it comes
to asking someone more than once to follow established conventions, then
yes, I will say something about it.
seriously, put down your mouse and your pocket protector, open up you
front door, you know, the big rectangle thing in the front of your
house, step through it and take a deep breath.

Too bad that my front door isn't rectangular. It is curved (no square
corners on it at all).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top