JavaScript set input value in while loop -
the code below:
v1 = document.getelementbyid('double').value; while (v1 < 10) { v1++; = new date().gettime(); while(new date().gettime() < + 1000){} document.getelementbyid('inputarea').value = v1; }
inputarea text box has 1 number, want increase number 1 ever second until reaches 10. problem inputarea shows last value 10, supposed ....7, 8, 9 10.
you can use setinterval
var timerid = setinterval(function(){ v1 = parseint(document.getelementbyid('double').value,10); if(v1 == 10){ clearinterval(timerid) } else{ document.getelementbyid('double').value = (v1+1) } },1000);
<input id="double" value="1" />
Comments
Post a Comment