Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Countdown timer with hours, minutes, and seconds

    Hey everyone,

    I'm working on a project that will take user input from 2 text boxes, representing hours and minutes, and then displaying a countdown timer until they hit 0. I am a newbie at javascript and am struggling to get this to work appropriately.

    I'm currently building this in an asp.net web app. I have a table which contains the text boxes, as well as a start button which I want to start the timer with. I've looked online for similar projects but there doesn't seem to be anything with taking user input from text boxes and displaying a countdown timer in HH:MM::SS format.

    If anyone could help me that would be great!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    We have just answered almost the same question at a thread with the silly title Feeling beaten and bloodied.

    You can easily adapt the script I supplied in the above thread to take input from textboxes but naturally you must ensure that the user inputs into those textboxes are numbers within a valid range. You will need to use Javascript to validate. onblur = "checkHours()".

    Assuming they are, you can start the timer with

    startTimer((hours * 60) + mins) * 60); // i.e. number of seconds of countdown

    I expect you realise that the countdown is only active while the user remains on the site. Will they hang around for hours? If you want the timer to resume in another browser session you will need to use a cookie.

    Quizmaster: What is the English equivalent of the German word Bürgermeister? Is it a cook, a postman or a mayor?
    Contestant: A cook, but it seems a bit obvious.
    Last edited by Philip M; 05-19-2014 at 01:27 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,627
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    Quote Originally Posted by Philip M View Post
    Quizmaster: What is the English equivalent of the German word Bürgermeister? Is it a cook, a postman or a mayor?
    Contestant: A cook, but it seems a bit obvious.
    That’s a good one.


  •  

    Posting Permissions

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