#16
  1. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
  2. #17
  3. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Need Help with Countdown Timer


    Hi,

    Like many I am new to all of this and am in need of help. I can get the code to work without a problem, but what I need is to be able to use a future date and time to create the difference. Any recommendations or help would be extremely appreciated.

    Thanks
    Gary
  4. #18
  5. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Originally Posted by gnelson
    Hi,

    Like many I am new to all of this and am in need of help. I can get the code to work without a problem, but what I need is to be able to use a future date and time to create the difference. Any recommendations or help would be extremely appreciated.

    Thanks
    Gary
    Hi Gary and welcome to the forum!

    Your wish is my command.. added support for future date as part of the advanced timer.
    download the new AdvancedCountDown.zip from the first post and then you can use
    such code to initialize timer from future date:
    Code:
    ActivateCountDown("CountDownPanel", [22, 6, 2011, 22, 30, 30], "CountDownEnded")
    the format of the array is:
    day, month, year, hour, minute, second
    if you wonder why array it's to prevent "date format hell", where different machines
    are using different date formats, thus giving string is very risky.
    (for example suppose you put in the code "10/1/2011 8:00:00" then on
    one machine it will be parsed as January 10th while in other browser
    it will be parsed as October the 1st - see my point? )

    in case you give date in the far future, you better display the remaining time in
    more friendly format, for example:
    Code:
    <span class="CountDownPanel" id="CountDownPanel" time_format="%d days, %h hours %m minutes and %s seconds"></span>
    otherwise there's little meaning in huge numbers counting down.

    good luck, let me know if you have any problem or question.
    Last edited by Shadow Wizard; June 24th, 2010 at 07:56 AM.
  6. #19
  7. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0
    I am humbled oh great one! Thank you so very very much. I can again I can see where I will have many uses for this. I had another thought as I was working with it today. What about instead of displaying days over 365 (366) as adding years in the time format? Just curious and again thank you.
  8. #20
  9. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Originally Posted by gnelson
    I am humbled oh great one! Thank you so very very much. I can again I can see where I will have many uses for this. I had another thought as I was working with it today. What about instead of displaying days over 365 (366) as adding years in the time format? Just curious and again thank you.
    My pleasure!

    Regarding the request for years, think about it.
    Assume second is our basis. Then what is a minute? 60 seconds.
    What is an hour? 60 minutes.
    What is a day? 24 hours.
    What is a week? 7 days.
    And... that's it!

    Anything more than a week can't be measured by absolute seconds amount.

    Month can be 28, 29, 30 or 31 days.

    Year is 12 months but can be 365 or 366 days.

    It's possible to simply divide the "days" variable in 365 and show it but
    it won't be accurate so I prefer to avoid it - if you insist I'll put something
    quick for you, but won't publish it in the main post.
  10. #21
  11. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0
    It is not a problem or something that I need. I was just thinking that it could be useful in cases where you want to project outward of a number of years.

    Along that line of thought though, I see what you mean when you say that the timer is based on seconds. So if one was wanting to make a clock that reflected years days hours and minutes, would one not base the the logic on days? I guess I'm just thinking out loud so to speak.

    Again, I appreciate what you have given so far and thank you!

    Gary


    Originally Posted by Shadow Wizard
    My pleasure!

    Regarding the request for years, think about it.
    Assume second is our basis. Then what is a minute? 60 seconds.
    What is an hour? 60 minutes.
    What is a day? 24 hours.
    What is a week? 7 days.
    And... that's it!

    Anything more than a week can't be measured by absolute seconds amount.

    Month can be 28, 29, 30 or 31 days.

    Year is 12 months but can be 365 or 366 days.

    It's possible to simply divide the "days" variable in 365 and show it but
    it won't be accurate so I prefer to avoid it - if you insist I'll put something
    quick for you, but won't publish it in the main post.
  12. #22
  13. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Having timer persist over multiple pages


    Mr. Wizard!

    I am trying to use the AdvancedCountDown script on a multi-page website to provide a 30 minute timer. The timer is set, and reset anytime the user accesses a shopping cart page to keep them from hoarding items. What I am trying unsuccessfully to do is display the timer on other pages they may navigate to from the cart. I have the timer working fine on the cart using:

    <script type="text/javascript">
    window.onload=WindowLoad;
    function WindowLoad(event) {
    ActivateCountDown("CountDownPanel", 20, "CountDownEnded");
    }
    </script>

    and

    <div>Cart Expires in <span id="CountDownPanel" time_format="%m:%s" time_addzero="1"></span></div>

    (BTW, I added a variable in the _cdt_ApplyCountdownText function to add leading zeros for custom formats using the "time_addzero" attribute).

    It seems that I should be able to write a function for all other pages to display the counter without resetting the time -- something like:

    window.onload=WindowLoad;
    function WindowLoad(event) {
    DisplayCountDown("CountDownPanel");
    }

    which would show the counter and show the Alert upon expiring.

    Any suggestions as to where to start?

    Thanks in advance.
    Bob
  14. #23
  15. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Hi Bob and thank for using my code!

    You need to store the amount of seconds left globally, most simple
    is inside Session variable, then it won't get reset every page hit.
    It was asked and answered before:
    http://forums.aspfree.com/asp-develo...es-358610.html

    If you have any question regarding the above answer please
    reply there, otherwise feel free to ask here, for example if
    I misunderstood your problem.
  16. #24
  17. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Thanks


    Originally Posted by Shadow Wizard
    Hi Bob and thank for using my code!

    If you have any question regarding the above answer please
    reply there, otherwise feel free to ask here, for example if
    I misunderstood your problem.
    Your answer was right on point. THANKS!
  18. #25
  19. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Adding a start and reset button?


    I have been looking for a code just like this. I would like to run 8 different instances of timers but I would like to start them my self with a start button. I am new to java and don't know how to do this my self.
    I would also like to have rest button that will reset the timer to set amount of time (4 hours).

    If anyone could show me what needs to be changed I would greatly appreciate it.
  20. #26
  21. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Originally Posted by rangerr
    I have been looking for a code just like this. I would like to run 8 different instances of timers but I would like to start them my self with a start button. I am new to java and don't know how to do this my self.
    I would also like to have rest button that will reset the timer to set amount of time (4 hours).

    If anyone could show me what needs to be changed I would greatly appreciate it.
    The code in AdvancedCountDown.js already support both things.

    In my existing examples, there is this line in the WindowLoad function:
    Code:
    ActivateCountDown("CountDownPanel1", 100, "CountDownEnded1");
    To have the counter start by button click, just remove that line from the WindowLoad function and instead have such button:
    Code:
    <button type="button" onclick="ActivateCountDown('CountDownPanel1', 100, 'CountDownEnded1');">Activate first countdown</button>
    As for Reset also possible using existing code, here is the button you need:
    Code:
    <button type="button" onclick="SetInitialTime('CountDownPanel1', 14400);">Reset Timer</button>
    The first parameter sent to SetInitialTime is the ID of the panel holding the counter, the second is the desired amount of seconds: 14400 seconds are four hours.
  22. #27
  23. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0
    I got the buttons working but i was wondering how to get the 4:00:00 to show before you click the activate countdown button but not start counting down. also when the counter reaches 00:00:00 change to a text string?
  24. #28
  25. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Originally Posted by rangerr
    I got the buttons working but i was wondering how to get the 4:00:00 to show before you click the activate countdown button but not start counting down.
    Simple enough.. in the WindowLoad function just activate the counter then deactivate it right away:
    Code:
    function WindowLoad(event) {
    	ActivateCountDown("CountDownPanel1", 100, "CountDownEnded1");
    	DeactivateCountDown('CountDownPanel1');
    }
    Then have the button like this:
    Code:
    <button type="button" onclick="ActivateCountDown('CountDownPanel1');">Activate first countdown</button>
    Originally Posted by rangerr
    also when the counter reaches 00:00:00 change to a text string?
    Have this in the function called when the timer is finished:
    Code:
    function CountDownEnded1()
    {
    	alert("the time for the first counter has expired!");
    	document.getElementById("CountDownPanel1").innerHTML = "Time Over";
    }
    You can put HTML in there and also change the "look and feel" by changing CSS class - let me know if you need such thing.
  26. #29
  27. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Thank You So much!


    This helps me a lot.
  28. #30
  29. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0
    Dear Shadow Wizard,

    I am novice, newbie or beginner in HTML and code designing.
    Thats why I used blogger's WYSIWYG to create my website.

    I post an article every alternate day. Now, I want to generate one counter for my blog which restart after every (48 Hours) 2 days.

    I little know about scripts so please advise which code to put in head and which in body. Or blogger allows me to put html code as widget. So simple javascript is also an option.

    Hear is my blog address just in case: sharadthakars.blogspot.com

    Thanks in advance.


    Originally Posted by Shadow Wizard
    Simple enough.. in the WindowLoad function just activate the counter then deactivate it right away:
    Code:
    function WindowLoad(event) {
    	ActivateCountDown("CountDownPanel1", 100, "CountDownEnded1");
    	DeactivateCountDown('CountDownPanel1');
    }
    Then have the button like this:
    Code:
    <button type="button" onclick="ActivateCountDown('CountDownPanel1');">Activate first countdown</button>

    Have this in the function called when the timer is finished:
    Code:
    function CountDownEnded1()
    {
    	alert("the time for the first counter has expired!");
    	document.getElementById("CountDownPanel1").innerHTML = "Time Over";
    }
    You can put HTML in there and also change the "look and feel" by changing CSS class - let me know if you need such thing.

Similar Threads

  1. ASP countdown timer
    By ben.r in forum ASP Development
    Replies: 4
    Last Post: August 8th, 2005, 09:55 AM
  2. Small Javascript Timer Problem
    By Scooty in forum ASP Development
    Replies: 0
    Last Post: June 13th, 2005, 01:43 PM
  3. Replies: 4
    Last Post: January 27th, 2005, 10:54 PM
  4. help, make timer! ASP & Javascript
    By rwahdan in forum ASP Development
    Replies: 1
    Last Post: September 19th, 2004, 08:49 AM
  5. Javascript Timer
    By Matt71 in forum HTML, JavaScript And CSS Help
    Replies: 2
    Last Post: May 21st, 2004, 04:58 AM

IMN logo majestic logo threadwatch logo seochat tools logo