I have the following code here I was wondering how would i have a label that would calculate the total time of all the timers running.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript">
$(document).ready(function () {
$("#btn1Start").click(function () {
timer1 = setInterval("$.do_time('timer1')", 1000);
$(this).attr("disabled", true);
});
$("#btn2Start").click(function () {
timer2 = setInterval("$.do_time('timer2')", 1000);
$(this).attr("disabled", true);
});
$("#btn3Start").click(function () {
timer3 = setInterval("$.do_time('timer3')", 1000);
$(this).attr("disabled", true);
});
});
//Timer JQuery function
(function ($) {
$.do_time = function(timerID) {
var time = ($("#" + timerID).html()).split(':');
var hour = parseInt(time[0], 10);
var minute = parseInt(time[1], 10);
var second = parseInt(time[2], 10) + 1;
if (second > 59) {
second = 0;
minute++;
}
if (minute > 59) {
minute = 0;
hour++;
}
$("#" + timerID).html((hour>9?hour:'0'+hour) +':'+ (minute>9?minute:'0'+minute) +':'+ (second>9?second:'0'+second));
} //End Doo time function
})(jQuery);
</script>
</head>
<body>
<table width="160">
<tr>
<td id="timer1">00:00:00</td>
<td><input type="button" id="btn1Start" value="button1" /></td>
</tr>
<tr>
<td id="timer2">00:00:00</td>
<td><input type="button" id="btn2Start" value="button2" /></td>
</tr>
<tr>
<td id="timer3">00:00:00</td>
<td><input type="button" id="btn3Start" value="button3" /></td>
</tr>
</table>
</body>
</html>
Open in new window
To a specific label called lbttime