help finding this

Discussion in 'Javascript' started by Bob, Aug 7, 2006.

  1. Bob

    Bob Guest

    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
    Bob, Aug 7, 2006
    #1
    1. Advertising

  2. 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
    Bart Van der Donck, Aug 7, 2006
    #2
    1. Advertising

  3. Bob

    RobG Guest

    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
    RobG, Aug 8, 2006
    #3
  4. Bob

    Bob Guest

    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
    Bob, Aug 8, 2006
    #4
  5. 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
    Bart Van der Donck, Aug 8, 2006
    #5
  6. JRS: In article <>,
    dated Mon, 7 Aug 2006 21:08:27 remote, seen in
    news:comp.lang.javascript, RobG <> 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.
    Dr John Stockton, Aug 8, 2006
    #6
  7. JRS: In article <>,
    dated Tue, 8 Aug 2006 08:52:59 remote, seen in
    news:comp.lang.javascript, Bart Van der Donck <> 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.
    Dr John Stockton, Aug 8, 2006
    #7
  8. Bob

    Bob Guest

    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 <>,
    > dated Mon, 7 Aug 2006 21:08:27 remote, seen in
    > news:comp.lang.javascript, RobG <> 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.
    Bob, Aug 9, 2006
    #8
  9. Bob

    Randy Webb Guest

    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/
    Randy Webb, Aug 9, 2006
    #9
  10. Bob

    Bob Guest

    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/
    Bob, Aug 9, 2006
    #10
  11. Bob

    Evertjan. Guest

    Bob wrote on 09 aug 2006 in comp.lang.javascript:
    > Randy Webb wrote:
    >> 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.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Aug 9, 2006
    #11
  12. Bob

    Randy Webb Guest

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


    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Aug 10, 2006
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colby L. Canutt

    Need help finding LRM Draft

    Colby L. Canutt, Sep 3, 2004, in forum: VHDL
    Replies:
    0
    Views:
    444
    Colby L. Canutt
    Sep 3, 2004
  2. rootz anabo
    Replies:
    3
    Views:
    545
    sarsizz
    Jan 2, 2005
  3. Boris Pelakh
    Replies:
    3
    Views:
    455
    Purl Gurl
    Apr 8, 2004
  4. News
    Replies:
    4
    Views:
    392
    Eliyahu Goldin
    Jul 20, 2004
  5. =?Utf-8?B?TGlvcg==?=

    Desperately need help finding connection leak

    =?Utf-8?B?TGlvcg==?=, Oct 30, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,648
    David Browne
    Oct 30, 2004
Loading...

Share This Page