Solved

total time

Posted on 2010-11-08
3
231 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:stargateatlantis
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
sam2912 earned 500 total points
ID: 34084537

<!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);
	});
	totaltimer = setInterval("$.displayTotal('totaltimer')", 1000);
});
//Timer JQuery function
(function ($) {
   totaltime = "00:00:00";
	$.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;
		
		var ttime = totaltime.split(':');
		var thour = parseInt(ttime[0], 10);
		var tminute = parseInt(ttime[1], 10);
		var tsecond = parseInt(ttime[2], 10) + 1;
		
		if (second > 59) {
			second = 0;
			minute++;
		}
		if (minute > 59) {
			minute = 0;
			hour++;
		}
		if (tsecond > 59) {
			tsecond = 0;
			tminute++;
		}
		if (tminute > 59) {
			tminute = 0;
			thour++;
		}
		
		time = (hour>9?hour:'0'+hour) +':'+ (minute>9?minute:'0'+minute) +':'+ (second>9?second:'0'+second);
		$("#" + timerID).html(time);
		totaltime = "" + (thour>9?thour:'0'+thour) +':'+ (tminute>9?tminute:'0'+tminute) +':'+ (tsecond>9?tsecond:'0'+tsecond);
	} //End Doo time function
	$.displayTotal = function(labelID) {
		$("#" + labelID).html(totaltime);
	}
})(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>
   <tr>
      <td id="totaltimer">00:00:00</td>
      <td></td>
   </tr>
</table>
</body>
</html>

Open in new window

0
 

Author Comment

by:stargateatlantis
ID: 34084572
How would I assign the total time
To a specific label called lbttime
0
 
LVL 14

Expert Comment

by:sam2912
ID: 34084659
totaltimer = setInterval("$.displayTotal('lbttime')", 1000);
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now