I've just created this working example for your with JavaScript / jQuery.
I'm a jQuery fan so,..
Code: Select all
<form method='post' onSubmit='return false;'>
<input type='button' id='indicator' data-state='start' value='Start'> <input type='button' id='reset' value='Reset timer'>
</form>
<span id='loop'>1</span>
Code: Select all
var counterInterval;
function count(element) {
var loop = parseInt($('#'+element).text());
console.log($('#'+element).text(loop+1));
}
$(function() {
$('#indicator').on('click', function() {
var state = $(this).data('state');
var loop = parseInt($('#loop').text());
if (state == 'start') {
$(this).data('state', 'stop');
$(this).val('Stop');
window.counterInterval = setInterval('count("loop");', 1000);
} else if (state == 'stop') {
$(this).data('state', 'start');
$(this).val('Start');
clearInterval(window.counterInterval);
}
});
$('#reset').on('click', function() {
if ($('#indicator').data('state') == 'stop') {
$('#indicator').trigger('click');
}
$('#loop').text('1');
});
});
I also want to say you need to try things yourself too..
So see if this can help you out a bit.
The jQuery library is downloadable at their website.