Created
January 14, 2016 14:11
-
-
Save Mashpy/e0d53488184791b69bfc to your computer and use it in GitHub Desktop.
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
<countdown>00:00:00</countdown> | |
<input type="hidden" name="checkyear" id="checkyear" value=""> | |
<script> | |
var countdown = document.getElementsByTagName('countdown')[0], | |
start = document.getElementById('start'), | |
stop = document.getElementById('stop'), | |
clear = document.getElementById('clear'), | |
seconds = 0, minutes = 0, hours = 0, | |
t; | |
function add() { | |
seconds++; | |
if (seconds >= 60) { | |
seconds = 0; | |
minutes++; | |
if (minutes >= 60) { | |
minutes = 0; | |
hours++; | |
} | |
} | |
countdown.textContent = (hours ? (hours > 9 ? hours : "0" + hours) : "00") + ":" + (minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") + ":" + (seconds > 9 ? seconds : "0" + seconds); | |
document.getElementById('checkyear').value = countdown.textContent; | |
timer(); | |
} | |
function timer() { | |
t = setTimeout(add, 1000); | |
} | |
timer(); | |
/* Stop button */ | |
stop.onclick = function() { | |
clearTimeout(t); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment