<html> <head> <title> Start and stop a clock </title> </head> <body> <input type
ID: 3547678 • Letter: #
Question
<html>
<head>
<title> Start and stop a clock </title>
</head>
<body>
<input type="text" size= "60" id="theclock" />
<script type="text/javascript">
var setIntervalID = window.setInterval("setClock()",1000);
function setClock()
{
var now = new Date();
document.getElementById("theclock").value=now.toLocaleString();
}
function stopClock()
{
clearIntervalID=window.clearInterval(setIntervalID);
}
</script>
<button>Stop</button>
</body>
</html>
Explanation / Answer
<html>
<head>
<title> Start and stop a clock </title>
</head>
<body>
<input type="text" size= "60" id="theclock" />
<script type="text/javascript">
var setIntervalID = window.setInterval("setClock()",1000);
function setClock()
{
var now = new Date();
document.getElementById("theclock").value=now.toLocaleTimeString();
}
function stopClock()
{
clearIntervalID=window.clearInterval(setIntervalID);
}
</script>
<button>Stop</button>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.