Do you have sample code to create html stopwatch?

Asked By 20 points N/A Posted on -
qa-featured

My groupmates are making a system using html with an embedded stopwatch on it. We want to ask for ideas or samples on what is the code to create html stopwatch. 

SHARE
Best Answer by Vivian Adrit
Best Answer
Best Answer
Answered By 5 points N/A #141111

Do you have sample code to create html stopwatch?

qa-featured

Dear Elsietbrown,

HTML is used to create the structure of the page. But if you want to embed a stopwatch in your page then you will probably have to use Javascript. There are a lot of tutorials and sample codes to for a sample stopwatch on the net. I'm providing you with a link that has a complete tutorial on how to make a stopwatch using JavaScript.

Thanks and hope it helped. Happy Coding.

Answered By 0 points N/A #141112

Do you have sample code to create html stopwatch?

qa-featured

Hello Elsietbrown,

You have create stopwatch by javascript and the code is given below, you can make a timer with start and stop button,



<!DOCTYPE html>
<html>
<body>

<p>Click the first button to display the current time, and the second button to stop the time.</p>
<button onclick="myFunction()">Try it</button>
<button onclick="myStopFunction()">Stop time</button>

<script>
var myVar;

function myFunction()
{
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>

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

</body>
</html>

 

Related Questions