Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > help finding this

Reply
Thread Tools

help finding this

 
 
Bob
Guest
Posts: n/a
 
      08-07-2006
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

 
Reply With Quote
 
 
 
 
Bart Van der Donck
Guest
Posts: n/a
 
      08-07-2006
Bob wrote:

> 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,

--
Bart

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      08-08-2006

Bob wrote:
> 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>


--
Rob

 
Reply With Quote
 
Bob
Guest
Posts: n/a
 
      08-08-2006
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.

RobG wrote:
> Bob wrote:
> > 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>
>
>
> --
> Rob


 
Reply With Quote
 
Bart Van der Donck
Guest
Posts: n/a
 
      08-08-2006
Bob wrote:

> 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.

--
Bart

 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      08-08-2006
JRS: In article <(E-Mail Removed). com>,
dated Mon, 7 Aug 2006 21:08:27 remote, seen in
news:comp.lang.javascript, RobG <(E-Mail Removed)> posted :
>Bob wrote:


>> I am not a js programmer,


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.

--
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.
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      08-08-2006
JRS: In article <(E-Mail Removed). com>,
dated Tue, 8 Aug 2006 08:52:59 remote, seen in
news:comp.lang.javascript, Bart Van der Donck <(E-Mail Removed)> posted :
>Bob wrote:
>
>> 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).


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

Read the newsgroup FAQ.
--
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.
 
Reply With Quote
 
Bob
Guest
Posts: n/a
 
      08-09-2006
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..

Dr John Stockton wrote:
> JRS: In article <(E-Mail Removed). com>,
> dated Mon, 7 Aug 2006 21:08:27 remote, seen in
> news:comp.lang.javascript, RobG <(E-Mail Removed)> posted :
> >Bob wrote:

>
> >> I am not a js programmer,

>
> 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.
>
> --
> 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.


 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      08-09-2006
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Bob
Guest
Posts: n/a
 
      08-09-2006
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....



Randy Webb wrote:
> 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.
>
> --
> Randy
> comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
> Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding Server... Finding Host.... enough already!!! Leesa_Tay@softhome.net Computer Support 2 01-20-2006 10:23 AM
Help finding a firefox extension. Don't Talk To Me About Problems Firefox 1 10-05-2005 06:54 AM
help needed in finding good hdl textbooks rootz anabo VHDL 3 01-02-2005 03:44 AM
Need help finding LRM Draft Colby L. Canutt VHDL 0 09-03-2004 05:42 AM
Help finding wireless network OVS Wireless Networking 3 08-16-2004 10:09 PM



Advertisments