Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Web Design, HTML And CSS Forums (http://www.go4expert.com/forums/web-design-forum/)
-   -   stopwatch !!! (http://www.go4expert.com/forums/stopwatch-t21779/)

gsingla4u 16Apr2010 09:02

stopwatch !!!
 
i want to create a Stopwatch but only with "setinterval" & "setTimeout" functions ....

satyedra pal 22Apr2010 13:44

Re: stopwatch !!!
 
Following is the Coding of stopwatch.which will generate only the seconds in the textbox and with start/stop and reset button.It's coding is written in the java script within html.
HTML Code:

<html>
<HEAD>
<SCRIPT LANGUAGE= "JavaScript">

var sec = 0;
var secc = 0;
function setinterval() {
if (secc == 0)
{
secc= 1;
a = new Date();
a.setTime(a.getTime() - sec);
}
else
{
secc = 0;
cur = new Date();
sec= cur.getTime() - a.getTime();
document.watch.time.value = sec ;
 }
}
function treset() {
secc = 0;
sec= 0;
document.watch.time.value = sec ;
}
function display()
{
setTimeout("display()", 100);
if (secc== 1) 
{
cur = new Date();
sec = cur.getTime() - a.getTime();
document.watch.time.value = sec;
  }
}
</script>
</head>
<BODY onLoad="display()">

<FORM NAME="watch">
<input type ="text" Name="time">
<input type="button" Name="button" VALUE="Start/Stop" onClick="setinterval()">
<input type="button" NAME="reset" VALUE="Reset" onClick="treset()">
</FORM>

</body>
</html>


gsingla4u 23Apr2010 18:02

Re: stopwatch !!!
 
thnx a lot !!!


All times are GMT +5.5. The time now is 10:06.