Friday, 31 August 2018

Clock Wise / Anti Clock Wise Stopwatch in JavaScript

:: Code ::

<html>
<head>
<title>stopwatch</title>
<script type="text/javascript">
var c=60;
var c2=0;
var t,t2;
function stopCount()
{
clearTimeout(t)
}
function stopCount2()
{
clearTimeout(t2)
}
function timedCount()
{
document.getElementById('txt').value=c
c=c-1
if(c==-1)
{
alert("time over")
stopcount()
}
t=setTimeout("timedCount()",1000)
}
function timedCount2()
{
document.getElementById('txt2').value=c2
c2=c2+1
if(c2==61)
{
alert("time over")
stopcount2()
}
t=setTimeout("timedCount2()",1000)
}
</script>
</head>
<body>
<center>
<form>
 <input type="text" id="txt">
 <input type="button" value="Start stopwatch (Anti Clock Wise)" onClick="timedCount()">
 <input type="button" value="Stop" onClick="stopCount()">
 <br/>
 <br/>
 <input type="text" id="txt2">
 <input type="button" value="Start stopwatch (Clock Wise)" onClick="timedCount2()">
 <input type="button" value="Stop" onClick="stopCount()">
</form>
<center>
</body>
</html>

:: Example ::