I want put back the value of my setTimeout to 30 when I click on button r2 after having clicked on button r1, which calls clearTimeout.
I tried something, but it puts back the number to 30, then goes back to the number it was before.
Here is the code:
JS
$(document).ready(function () {
var numb = 30;
var numba = 100;
var timer = null;
function comptage() {
timer = setTimeout(comptage, 1000);
$('#test').html(numb);
$("#progressbar").progressbar({
value: numba
});
numb--;
numba = numba - (numba / numb);
if(numb < 0) {
numb = 0;
numba = 0;
}
};
comptage();
$("#r1").click(function () {
clearTimeout(timer);
});
$("#r2").click(function () {
timer = setTimeout(comptage, 1000);
var numb = 30;
var numba = 100;
$('#test').html(numb);
$("#progressbar").progressbar({
value: numba
});
numb--;
numba = numba - (numba / numb);
});
});
HTML
<div id="r1">bouton desactiver</div>
<div id="r2">bouton réactiver</div>
<div id ="affichage_point">
<div id="bardivs">
<div id="progressbar"></div>
<div id="test"></div>
</div>
</div>
<?php if (isset($_SESSION['timer'])){ ?>
<div id ="r6">
<?php echo $_SESSION['timer'] ?>
</div>
<br/>
<?php } ?>
In the click handler for
r2, you have:These will create new local variables, and won’t touch the global variables. Remove the
varhere to have it update the global variables.