I'm obviously new to this, and I can't get my head around this problem.
I'm creating a timer that stops and starts, afterwards the startstoptimes have to be stored in Mysql.
But for now I can't even get the timer to work properly. I'd like the time formatted as hh:mm. And the totaltime gives me a number for some reason...
This is a code so far:
<html>
<head>
<title>Timer</title>
<link rel="stylesheet" href="styles/style.css" media="all" />
<div>
<?php include 'menu.php';?>
<script type="text/javascript">
var t;
var timer_is_on = 0;
var StartTime = new Date();
var RunTime = new Date();
var EndTime = new Date();;
var TotalTime = new Date();
function timedCount() {
var RunTime = new Date();
document.getElementById('runtime').value = RunTime;
t = setTimeout("timedCount()", 1000);
}
function doTimer() {
if (!timer_is_on) {
var StartTime = new Date();
document.getElementById('starttime').value = StartTime;
timer_is_on = 1;
timedCount();
}
}
function stopCount() {
var EndTime = new Date();
var EndTimeMs = EndTime.getTime();
TotalTime = EndTime - StartTime;
document.getElementById('totaltime').value = TotalTime;
clearTimeout(t);
timer_is_on = 0;
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onclick="doTimer()" />
<input type="text" id="starttime" />
<input type="text" id="runtime" />
<input type="text" id="totaltime" />
<input type="button" value="Stop count!" onclick="stopCount()" />
</form>
</body>
</html>