Need some help with this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Need some help with this code

I want to make a progress bar which only clickable once and stops when the other button is pressed but I am having problem in the clicking only once part as u can see in the below code when u press the button more than once u can speed up the progress bar but I don't want it to happen. so any help will be appreciated! https://code.sololearn.com/WHT822ao9n7m/?ref=app

15th Jul 2017, 11:54 AM
_Retr0/-
_Retr0/- - avatar
3 Answers
+ 4
// Quite different solution: var btm; var ti = null; // for later easiest handling var v = 0; function c() { // dont use 'var' keyword else you create a local variable rather than use the global var ^^ // and test the value of ti: if null you start the serInterval, else you cancel the setInterval and reset ti: if (ti===null) ti = setInterval(m,100); else { clearInterval(ti); ti = null; } } function m() { var btm = document.getElementById("p").value = v++; }
15th Jul 2017, 12:14 PM
visph
visph - avatar
+ 15
var btm; var ti; var v = 0; function c() { var ti = setInterval(m,100); c = function() {}; } function m() { var btm = document.getElementById("p").value = v++; } //Disable function after click
15th Jul 2017, 12:08 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
thanks a lot
15th Jul 2017, 12:11 PM
_Retr0/-
_Retr0/- - avatar