David said:
Im not sure where to find all the documentation i need for this? I need
to timer since a start button has been pushed, and show a counter on a
page. If they click stop i want to keep the time, and carry on
incrementing it if they click start again.
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css" media="all">
.clock {
text-align:center;
font-family: Courier, Courier New;
font-size: 30px;
font-weight: bold;
background-color: white;
border: 0px;
border-style: solid;
border-color: white;
}
body {
background-color: white;
}
</style>
<script language="javascript" type="text/javascript">
// 1000 = 1 second.
// A reliable 'real seconds' timer is only 1000 (or above)
// on nowadays machines, because CPU will slowdown the
// timer if it are small intervals.
// The lower the value, the longer your 'seconds' will become.
// If the real time is not important for you (you wrote about
// 'a counter'), you can set this value as low as you like.
var interval = 1000;
// These should be left as they are
var tijdID = null;
var tijdLoopt = false;
function stop_klok() {
if (tijdLoopt)
clearTimeout(tijdID);
tijdLoopt = false;
}
function toon_tijd() {
var now = new Date();
seconden = parseFloat(document.counterform.cf.value);
seconden = seconden + 1;
huidigeTijd = '';
if (seconden < 10)
huidigeTijd='00000'+seconden;
if (seconden < 100 && seconden >= 10)
huidigeTijd='0000'+seconden;
if (seconden < 1000 && seconden >= 100)
huidigeTijd='000'+seconden;
if (seconden < 10000 && seconden >= 1000)
huidigeTijd='00'+seconden;
if (seconden < 100000 && seconden >= 10000)
huidigeTijd='0'+seconden;
document.counterform.cf.value = huidigeTijd;
tijdID = setTimeout("toon_tijd()", interval);
tijdLoopt=true;
}
function start_klok() {
stop_klok();
toon_tijd();
}
</script>
</head>
<body>
<form name="counterform">
<center>
<input onFocus="blur();" type="text" name="cf"
size="13" class="clock" value="000000">
<br/>
<input type="button" value="Start" onClick="start_klok();">
<input type="button" value="Stop" onClick="stop_klok();">
</center>
</form>
</body>
</html>