0
People I got from a friend here on the forum a one button script with countdown, that when clicking starts the count. I really appreciate it because it is very good... there is only one problem, when I click more than once on the button the countdown accelerates, see the code
<script language="JavaScript">
function dispara( span ) {
conta( this, document.getElementById( span ) );
}
function conta( botao, contador ) {
botao.disabled=true;
if(contador.innerHTML==0) {
contador.innerHTML = 10;
botao.disabled=false;
return false;
}
contador.innerHTML = contador.innerHTML - 1;
setTimeout( function(){conta( botao, contador )}, 1000 );
}
</script>
<input type="button" value="botao1" onclick="dispara('s1')" class="btn">
<span id="s1">10</span>
<br/><br/>
<input type="button" value="botao2" onclick="dispara('s2')" class="btn">
<span id="s2">10</span>
Could you help me solve this problem?
The
this
indispara
is not the button (as the other function waits), and that is what is causing the problem.– bfavaretto
I need this, this serves to grab the button clicked, dispensing your ID
– Márcio Sebastião