function timerCountdown() {
var timeleft = document.getElementById("text").value;
timeleft -= 1;
displayTime.innerHTML = timeleft;
setInterval(timerCountdown, 1000);
}
Set Timer<input type="text" id="text" value="">
<br>
<span id="displayTime"></span>
<br>
<button onclick="timerCountdown()" type="button" id="button" value="submit">GENERATE</button>
I'm trying to create a countdown timer for my project, where users will be able to key in (in seconds) the value they want. However, my codes only stay at a number instead of counting down. Any help would be appreciated.
I tried creating a variable to get the element of the value, setting up an increment counter, and a setInterval, which the variable will minus the increment counter every second, but I don't think the increment counter works?
JS File
function timerCountdown() {
var timeleft = document.getElementById("text").value;
var counter = 0;
counter++;
displayTime.innerHTML = (timeleft - counter);
setInterval(timerCountdown,1000);
}
HTML File
<input type="text" id="text" style="display: none;">
<span id="displayTime"></span>
I expected the timer to be counting down, but instead all it does is subtract the value by 1 and stays there.