Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Time In Time Out

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Time In Time Out

    Ok so I have this code so far for a time in time out button, I want it to post within the app and show the wait time. I dont know where to go from here but it just is not working
    .

    <html>
    <head>

    <script type = "text/javascript">

    var timeInSecs;
    var ticker;

    function start(){
    var s = document.getElementById("period").value;
    document.getElementById("period").disabled = true;
    s = 4 // FOR TESTING
    startTimer(s);
    }

    function startTimer(secs){
    timeInSecs = parseInt(secs);
    ticker = setInterval("tick()",1000);
    tick(); // to start counter display right away
    }

    function tick() {
    var secs = timeInSecs;
    if (secs>0) {
    timeInSecs--;
    showTime(secs);
    }

    else {
    timeInSecs--;
    document.getElementById("countdown").style.color = "red";
    document.getElementById("countdown").innerHTML = "You have exceeded your time by " + Math.abs(timeInSecs) + " seconds";
    }
    }

    function showTime(secs) {
    var hours= Math.floor(secs/3600);
    secs %= 3600;
    var mins = Math.floor(secs/60);
    secs %= 60;
    var result = ((hours < 10 ) ? "0" : "" ) + hours + ":" + ( (mins < 10) ? "0" : "" ) + mins
    + ":" + ( (secs < 10) ? "0" : "" ) + secs;
    document.getElementById("countdown").innerHTML = result;
    }

    </script>

    </head>

    <select id = "period" onchange = "start()">
    <option value = "0">Select time required</option>
    <option value = "900">15 minutes</option>
    <option value = "1800">30 minutes</option>
    <option value = "2700">45 minutes</option>
    <option value = "3600">60 minutes</option>
    <option value = "4500">75 minutes</option>
    <option value = "5400">90 minutes</option>
    <option value = "6300">105 minutes</option>
    <option value = "7200">120 minutes</option>
    </select>

    <span id="countdown" style="font-weight: bold;"></span>

    </body>
    </html>

    I want to use this for different parts of the app and would like to be able to assign this to a specific function


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Time In Time Out

    Building your first app
    There will be plenty of time for timers after hello world.

Similar Threads

  1. Trying to set up servlet, JSP, and JSF for first time.
    By MeteoricDragon in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: August 11th, 2012, 08:27 PM
  2. [SOLVED] Help with time
    By usama8800 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 25th, 2012, 05:13 PM
  3. [SOLVED] How much time should I have on a program?
    By SOG in forum Java Theory & Questions
    Replies: 17
    Last Post: July 19th, 2011, 06:28 PM
  4. First Time
    By rayoung17 in forum Member Introductions
    Replies: 1
    Last Post: April 4th, 2011, 02:52 PM
  5. Using time
    By ellias2007 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 4th, 2010, 09:48 AM