I have a code for the progress bar and I want the progress bar repeat itself 10 times,in other words going from 0% to 100%, 10 times. I have created a for loop but the code only runs the ProgressBarSim function once.
Here is script:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
</head>
<body>
<script>
var sim;
var mm=0;
for (i = 0; i < 10; i++) {
var al=0;
var t=0;
function progressBarSim(al, t) {
var bar = document.getElementById('progressBar');
var status = document.getElementById('status');
bar.value = al;
status.innerHTML = al + "%";
al++;
sim = setTimeout(function(){ progressBarSim(al, t); }, 50);
if (al == 101) {
clearTimeout(sim);
var al=0;
var t=0;
}//end if
}//end function
}//end for
</script>
<form name="Calculation" method="post">
<progress id="progressBar" value="0" max="100" style="width:300px;"> </progress>
<span id="status"></span>
<input type="button" id="btn2" value="Start Acquisition" onclick="progressBarSim(0, 0)">
</form>
</body>
</html>
How can I make it to repeat itself?
progressBarSimdeclared in the for loop?progressBarSimduring every iteration of the for loop. But to answer why this isn't working it is because you never actually callprogressBarSimyou just declare it 10 times.