JavaScript to Start and Stop the Time



Hi Frnds, I waana
Show you how to Start and Stop the Time Using JavaScript...;






The Below Code is
used to Start and Stop the Time Using JavaScript






<!DOCTYPE html>


<html>


<body>






<p>A script on
this page Starts and Stops clock:</p>






<p id="demo"></p>






<div>




<form><input
type = "submit" value = "Start Time" style =
"float:left"></form>






<input type =
"submit" value = "Stop Time" style =
"margin-left:10px" onclick="myStopFunction()"
></div>






<script>


var myVar =
setInterval(function(){ myTimer() }, 1000);






function myTimer() {


var d = new
Date();


var t =
d.toLocaleTimeString();



document.getElementById("demo").innerHTML = t;


}






function
myStopFunction() {



clearInterval(myVar);


}


</script>






</body>


</html>






Observe carefully
this code






<p id =
demo”></p>





var myVar =
setInterval(function(){ myTimer() }, 1000);






function myTimer() {


var d = new
Date();


var t =
d.toLocaleTimeString();



document.getElementById("
demo").innerHTML = t;


}






This code is used to
display the Current System time, when page is loaded.





<input type =
"submit" value = "Stop Time" style =
"margin-left:10px"
onclick="myStopFunction()" >






function
myStopFunction() {



clearInterval(myVar);






When we click the
“Stop Time” Button, the myStopFunction() is called. It Stops the
Time.






<form><input
type = "submit" value = "Start Time" style =
"float:left"></form>






When we click the
“Start Time” Button, the Page will refresh so the time will start
again.






Try it...,








Have Nice Day...;


Comments

Popular posts from this blog

Android App Version Update using the following cordova cli commands

75 inspirational quotes that will change your life

Retrieval Image From DataBase and Display on WebPage by Using Servlets.