I've added a timer using a HTML5 progress bar. When clicking on a button, the bar is set on with the following function. It works well, but what I would like to add is trigger an action when the progress is over, and also be able to stop the progress when clicking on another button.
<progress value="0" max="40" id="pbar" ></progress>
<div id="start-stop">
<button id="start" onclick="start_countdown()">Start</button>
<button id="stop">Stop</button>
</div>
...
function start_countdown(){
var reverse_counter = 40;
var downloadTimer = setInterval(function(){
document.getElementById('pbar').value = 40 - --reverse_counter;
if(reverse_counter <= 0)
clearInterval(downloadTimer);
},1000);
}