We help IT Professionals succeed at work.
Get Started

Auto Start Timer

-Matthew-
-Matthew- asked
on
1,358 Views
Last Modified: 2012-04-26
Users always want changes...trying to modify this to auto start. I figure I just need to set theButton to Start and maybe do an onload event or is there a much easier way. In any case its not working for me. Thanks for your suggestions.

<script language="JavaScript" type="text/javascript">
<!--
var sec = 0;
var min = 0;
var hour = 0;

function stopwatch(text) {
   sec++;
  if (sec == 60) {
   sec = 0;
   min = min + 1;
   		if (min == 5)
   			{alert ('5 minutes have passed, I know, it seems longer.');
   			} 
   		if (min == 10)
   			{alert ('10 minutes have passed. All cheer!');
   			}
   }
  else {
   min = min; }
  if (min == 60) {
   min = 0; 
   hour += 1; }

if (sec<=9) { sec = "0" + sec; }
   document.clock.stwa.value = ((hour<=9) ? "0"+hour : hour) + " : " + ((min<=9) ? "0" + min : min) + " : " + sec;

  if (text == "Start") { document.clock.theButton.value = "Stop "; }
  if (text == "Stop ") { document.clock.theButton.value = "Start"; }

  if (document.clock.theButton.value == "Start") {
   window.clearTimeout(SD);
   return true; }
SD=window.setTimeout("stopwatch();", 1000);
}

function resetIt() {
  sec = -1;
  min = 0;
  hour = 0;
  if (document.clock.theButton.value == "Stop ") {
  document.clock.theButton.value = "Start"; }
  window.clearTimeout(SD);
 }
// -->
</script>

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE