Monday, 25 April 2016

Create A HTML Page Using JavaScript For StopWatch

Create A HTML Page Using JavaScript For StopWatch  There Should Be One Start And Stop Button And One Reset Button For Reset A Timer 

Code Start Here


stopwatch.html


<!DOCTYPE html>
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var ms = 0;
var state = 0;
function startstop()
{
if (state == 0)
{
state = 1;
then = new Date();
then.setTime(then.getTime() - ms);
}
else
{
state = 0;
now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
}
}
function swreset()
{
state = 0;
ms = 0;
document.stpw.time.value = ms;
}
function display()
{
setTimeout("display();", 5);
if (state == 1)
{
now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
}
}

</SCRIPT>
<title>HTML Table Cellpadding</title>
</head>
<body bgcolor="aqua" onLoad="display()">
<CENTER>
<font size="20"><FORM NAME="stpw">
Time:
<INPUT TYPE="text" Name="time">
<INPUT TYPE="BUTTON" Name="ssbutton" VALUE="Start/Stop" onClick="startstop()">
<INPUT TYPE="BUTTON" NAME="reset" VALUE="Reset" onClick="swreset()">
</font></FORM>
</CENTER>
</body>

</html>

Output:-

www.programmingwithbasics.com

www.programmingwithbasics.com


No comments:
Write comments

Recommended Posts × +