I need to update the time of setIntreval after clicking the button.
var seconds = 5;
<input id="new-time" />
<button id="new-time-submit">submit</button>
$("#new-time-submit").on("click", function(){
seconds = $("#new-time").val();
});
setInterval(function(){
alert(seconds);
// my codes
}, seconds*1000);
When the setInterval runs, it alerts new value but it repeats every 5 seconds as before. How can I chage the seconds value in setInterval time duration?