+ 3
Why clearInterval not working...
var stop = setInterval(autoFill,200); function autoFill(){ $(".ui-autocomplete-input:eq(0)").val("NEW DELHI - NDLS"); $(".ui-autocomplete-input:eq(1)").val("SHMATA VD KATRA - SVDK"); $(".hasDatepicker:eq(0)").val("19-05-2018"); $("[name='jpform:jpsubmit']:eq(0)").click(function(){clearInterval(stop);}); $("[name='jpform:jpsubmit']:eq(0)").click();}
5 Answers
+ 4
Fata1 Err0r well once before I made a script for a website...and I put the click event inside the function...and it worked well....but this time not working...I don't know....but the problem may be somewhere else....
+ 4
Fata1 Err0r I used setTimeout to execute the function and it is also putting the function in loop... amazing
+ 3
Button is getting clicked and the function bound to it is also being executed....but clearInterval didn't remove the timer....and function keeps on looping....
+ 3
Try putting your click event outside of the function that's being looped with the interval.
I put together a quick example for you so you can see it in action. If you post a link to your whole code, I can correct it if you can't get it working.
EXAMPLE:
https://code.sololearn.com/WUqY88ljyPtV/#html
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
</head>
<body>
<button id="clearInt" >Clear</button>
</body>
<script>
var stop = setInterval(function(){ console.log("Running"); }, 1000);
$('#clearInt').click(function(){
clearInterval(stop);
console.log("Stopped");
});
</script>
</html>
+ 3
Fata1 Err0r I got you....