Skip to content

Instantly share code, notes, and snippets.

@Mashpy
Created January 14, 2016 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mashpy/e0d53488184791b69bfc to your computer and use it in GitHub Desktop.
Save Mashpy/e0d53488184791b69bfc to your computer and use it in GitHub Desktop.
<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