Created
January 4, 2012 21:57
-
-
Save pedrocss/1562393 to your computer and use it in GitHub Desktop.
Timer Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = function () { | |
var timeout; | |
var MIN; | |
var SEC; | |
document.getElementById("startTimer").onclick=function(){startTimer()} | |
function startTimer(){ | |
MIN = document.getElementById("min").value; | |
SEC = document.getElementById("sec").value; | |
document.getElementById("startTimer").value = "Stop"; | |
document.getElementById("startTimer").id = "stopTimer"; | |
document.getElementById("stopTimer").onclick=function(){stopTimer()} | |
refreshTimer(MIN, SEC); | |
} | |
function stopTimer(){ | |
document.getElementById("stopTimer").value = "Start"; | |
document.getElementById("stopTimer").id = "startTimer"; | |
document.getElementById("startTimer").onclick=function(){startTimer()} | |
timeout = clearTimeout(timeout); | |
} | |
function refreshTimer(MIN, SEC){ | |
if(SEC == 0){ | |
MIN = MIN - 1; | |
SEC = 59; | |
}else{ | |
SEC = SEC - 1; | |
} | |
if(MIN+SEC > 0){ | |
document.getElementById("min").value = MIN; | |
document.getElementById("sec").value = SEC; | |
timeout = setTimeout(refreshTimer, 1000, MIN, SEC); | |
}else{ | |
document.getElementById("min").value = MIN; | |
document.getElementById("sec").value = SEC; | |
document.getElementById("stop").id = "start"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment