troubleshooting Question

Auto Start Timer

Avatar of -Matthew-
-Matthew- asked on
JavaScript
4 Comments1 Solution1361 ViewsLast Modified:
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>
ASKER CERTIFIED SOLUTION
dcowley

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros