HTML Code :
JavaScripts Code :
<input type="button" name="btn" id='btn' value="Start" onclick="to_start()";>
<br><br>
<div id=n1 style="z-index: 2; position: relative; right: 0px; top: 10px; background-color: #00cc33;
width: 100px; padding: 10px; color: white; font-size:20px; border: #0000cc 2px dashed; "> </div> <br>
<input type="button" name="btn" id='btn' value="Start" onclick="stop()";>
<br><br>
<div id=n1 style="z-index: 2; position: relative; right: 0px; top: 10px; background-color: #00cc33;
width: 100px; padding: 10px; color: white; font-size:20px; border: #0000cc 2px dashed; "> </div> <br>
<input type="button" name="btn" id='btn' value="Start" onclick="stop()";>
JavaScripts Code :
<script language=javascript>
var h=0;
var m=0;
var s=0;
function to_start(){
tm=window.setInterval('disp()',1000);
}
function stop(){
window.clearInterval(tm); // stop the timer
h=0;
m=0;
s =0;
}
function disp(){
// Format the output by adding 0 if it is single digit //
if(s<10){var s1='0' + s;}
else{var s1=s;}
if(m<10){var m1='0' + m;}
else{var m1=m;}
if(h<10){var h1='0' + h;}
else{var h1=h;}
// Display the output //
str= h1 + ':' + m1 +':' + s1 ;
var time=document.getElementById('n1').innerHTML=str;
// Calculate the stop watch //
if(s<59){
s=s+1;
}else{
s=0;
m=m+1;
if(m==60){
m=0;
h=h+1;
} // end if m ==60
}// end if else s < 59
// end of calculation for next display
}
</script>
var h=0;
var m=0;
var s=0;
function to_start(){
tm=window.setInterval('disp()',1000);
}
function stop(){
window.clearInterval(tm); // stop the timer
h=0;
m=0;
s =0;
}
function disp(){
// Format the output by adding 0 if it is single digit //
if(s<10){var s1='0' + s;}
else{var s1=s;}
if(m<10){var m1='0' + m;}
else{var m1=m;}
if(h<10){var h1='0' + h;}
else{var h1=h;}
// Display the output //
str= h1 + ':' + m1 +':' + s1 ;
var time=document.getElementById('n1').innerHTML=str;
// Calculate the stop watch //
if(s<59){
s=s+1;
}else{
s=0;
m=m+1;
if(m==60){
m=0;
h=h+1;
} // end if m ==60
}// end if else s < 59
// end of calculation for next display
}
</script>
0 comments:
Post a Comment