Results 1 to 7 of 7

Thread: Countdown to input time.

  1. #1
    Join Date
    Jun 2008
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Countdown to input time.

    Hi everyone

    Just need some help with a countdown script.... the one i have been using is a mix of a few, it has a input fields to enter the HH MM SS, than a onclick function to start the timer... When the time ends, the classname is changed.

    Confused yet lol, I attached the file so you can see what i mean.

    Now this workes fine but it has a few flaus
    1. It dosnt keep time, it eventully ends up a few second up to a few mins off.
    2. Im not a good programer thats why there is 1 script per clock lol.
    3. i cant think of anything els for now but you will probably find more.

    I have been looking at this script:
    http://www.dynamicdrive.com/dynamici...dhtmlcount.htm

    Just wondering if there is a way to change the script linkes, (or the one i attached) so that it has the same input fields as the one I attached, but instead of 4 clocks, is it poossible to just have one clock, that rolls over, so counts down to 1, than the second than the third and finally the forth, and at the end says somthing like complete...

    Thanx very much in advanced for taking the time to read this.
    Kirt

  2. #2
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    Ive noticed that the setInterval is not the most reliable of things. I wouldnt bake a cake by it but its good for general delay.
    Programmers are tools used to convert Caffeine to code

  3. #3
    Join Date
    Jun 2008
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Lol yep, and makes things worse when there is alot of loading within the same page, causes it to loose more and more time...

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If you continually reference a fresh Date object with each loop, depending upon the rest of the code, that should keep things on track. If you are relying on the interval to accurately accumulate time though, I can see your problem.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. The Following User Says Thank You to jscheuer1 For This Useful Post:

    kirtangl (08-13-2008)

  6. #5
    Join Date
    Jun 2008
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi jscheuer1

    How would I go about refreshing the data with each loop, or every minute etc, I have had some sucsess but I think I have some problems, the time switches from one set time to the wrong set time, back and forth every second... pretty funny really lol, but somewhat anying.

  7. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I must admit that I've only been following this thread in a general sort of way - with reason. In cases like this, fundamental concepts are sometimes more important than the actual code, which I'm fairly confident you can work up to your satisfaction once you get the idea. But I'll work with you until you get something that works for you.

    You should study the Date object, it will prove enlightening. However it has numerous properties, not all of which are applicable to your code.

    From what I can tell by skimming this thread, you want to create a reliable timer or reliable timers.

    Let's start simple. Say you want to show an alert 20 seconds from now:

    Code:
    <script type="text/javascript">
    function timer_1(){
    var later = new Date();
    later.setSeconds(later.getSeconds() + 20);
    var getIt = function(){
    var now = new Date().valueOf();
    if (now >= later.valueOf()){
    clearInterval(getIt.inv);
    alert('times up');
    }
    };
    getIt.inv = setInterval(getIt, 100);
    };
    timer_1();
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #7
    Join Date
    Jun 2008
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you, got that one working, sorry for the late delay, was away for a bit, probably a good time to work on this but didnt have access to a computer.

    Dosn't display anything, but with an onlooad funtion after 20 seconds it pops up with a Times up.. seems to do it twice lol but works.

    EDIT: Decided to read the script, dont need a onload event lol... my bad.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •