0
Why buttons work only once?
When I add to function to the buttons, it only work once. How can I make it works more than once. https://code.sololearn.com/WPwH97maEoDP/?ref=app
7 ответов
+ 1
You can always use javascript to make that happen. That is you can use addEventListener() to make buttons more responsive. 🙂🙂🙂
I hope it helps.
+ 7
Hello Allamprabhu Hiremath ,
In your stop function , you are clearing your interval 'Time'. which means basically deleting it. Again , in your start function , your are writing setInterval(moveUp , 2) but not assigning it to anything else. Thus , when you again run your stop function it clears "Time" which is undefined because you deleted it before. Thus , the progess does not stop. There is nothing wrong with your buttons.
function start()
{
time = setInterval(moveUp , 2);
}
instead of setInterval(moveUp , 2);
Have a good day,
Cheyat
+ 2
var time = setInterval(moveUp,1);
var count = 0;
var n = 10 ;
function moveUp (){
count += n ;
document.getElementById("a").innerHTML =
count ;
document.getElementById("meter").value = count ;
}
function stop(){
clearInterval(time);
n = 0 ;
}
function start(){
setInterval(moveUp,2);
n = 10 ;
}
+ 2
Allamprabhu Hiremath
if(document.getElementById('meter'))
{stop();}
in moveUp() function
+ 1
Js line 6
if(count<16000){count += 10 ;}
0
How to stop this count when it reaches to 16000
0
Thanks to all. Its work