Please login to start chat

ICT Solutions 25 Jun 2022, 11:39:36
Category : JavaScript Tutorials

timer (HTML DOM Window)

<!DOCTYPE html>
<html>
<head>
<title>Js Code Testing</title>
</head>
<body>
<button onclick = "startCount()">Start Count</button>
<input type = "text" id = "txt">
<button onclick = "stopCount()">Stop Count</button>
</body>
<script>
var c = 0;
var t;
var myTimer = 0;

function jsFun(){
document.getElementById("txt").value = c;
c++;
t = setTimeout(jsFun, 1000);
}

function startCount(){
if(!myTimer){
myTimer = 1;
jsFun();
}
}

function stopCount(){
myTimer = 0;
clearTimeout(t);
}
</script>
</html>

Comments:

No comment to show.

Available Services
Download Android Application