Wednesday, January 11, 2012

I can not get result after calling JavaScript function


I am working with Javascript StopWatch in C# web Aplication. But I don't get output from javascript. Below is my code.




<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript" language="JavaScript">
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();", 50);
if (state == 1) {now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
}
}
</script>
</head>
<body onload="display()">
<form id="form1" runat="server">
<div>
Time:
<input type="text" name="time"/>
<input type="button" name="ssbutton" value="Start/Stop" onclick="javascript:startstop()"/>
<input type="button" name="reset" value="Reset" onclick="javascript:swreset()"/>

</div>
</form>
</body>
</html>



I am new with javascript ,Where I am doing mistake?? Thank You...

No comments:

Post a Comment