Hello Friends today's I wanna show you how to create a Stopwatch and Counter with JavaScript code at first you have to open notepad and select and copy the below Counter code and past it to notepad and save it to Counter.html and see after saving open the file and see Wow you can do it ...... Here you go to see after something awesome Now you have to copy the stopwatch code and past the code to notepad and save it to Stopwatch.html and open the file which you save recently yahooo you did it 
Counter Code:-
<html>
<head>
<script type="text/javascript">
var c=0;
var t;
var timer_is_on=0;
function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000);
}
function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onClick="doTimer()">
<input type="text" id="txt">
</form>
<p>Click on the button above. The input field will count forever, starting at 0.</p>
</body>
</html>
Stopwatch Code:-
<html>
<head>
<script language="JavaScript">
var c1=0;
var c2=0;
var c3=0;
var o1=0;
var o2=0;
var o3=0;
ID=window.setTimeout("start();",100);
function start()
{
if (c1==59)
{
c1=00;;
if(c2==59)
{
c2=00;
}
else
c2++;
}
else
c1++;
if(c1==0||c1==1||c1==2||c1==3||c1==4||c1==5||c1==6||c1==7||c1==8||c1==9)
o1="0"+c1;
else
o1=c1;
if(c2==0||c2==1||c2==2||c2==3||c2==4||c2==5||c2==6||c2==7||c2==8||c2==9)
o2="0"+c2;
else
o2=c2;
if(c3==0||c3==1||c3==2||c3==3||c3==4||c3==5||c3==6||c3==7||c3==8||c3==9)
o3="0"+c3;
else
o3=c3;
document.forms[0].elements[0].value=o3+":"+o2+":"+o1;
ID=window.setTimeout("start();",100);
}
</script>
</head>
<body>
<form name="frm1">
<input type="text" name="timer1">
<input type="button" name="but1" value="start" onClick="c1=0; c2=0; c3=0; o1=0; o2=0;
o3=0; start();">
<input type=button name="but2" value="stop" onClick="window.clearTimeout(ID);">
</form>
</body>
</html>
Thanks for watching my tutorial ...Good Bye and Good Luck ...




0 comments:
Post a Comment