JSFiddle - React, Tailwind, and code Playground
by Academia
HTML
<p id="test"></p>
<form name="form1">
Enter timeout value:<input type="text" id="to"/></br></br>
Countdown: <input type="text" id="cd"/></br></br>
<input type="button" value="Start" onclick="start()" />
<input type="button" value="Stop" onclick="stop()" />
</form>
JavaScript
var timer;
function start(){
alert("hello");
document.getElementById("test").innerHTML = "test";
timer = setInterval(function(){myTimer()},1000);
}
function myTimer(){
var value = Number(document.getElementById("to").value);
if (value != 0){
document.getElementById("to").value = value - 1;
} else {
stop();
}
}
function stop(){
clearInterval(timer);
}