-Matthew-
asked on
Auto Start Timer
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
The stop watch code as it is works fine, starts, stops, etc. And yes, you are correct, I want it to automatically start when the page loads.
ASKER
The form code is as follows:
<form name="clock">
<input name="stwa" type="text" class="schoolheader2" style="text-align:center" value="00 : 00 : 00" size="12" />
<br />
<input type="button" name="theButton" onClick="stopwatch(this.value);" value="Start" />
<input type="button" value="Reset" onClick="resetIt();reset();" />
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I want to make sure that I understand what you're trying to accomplish. You've included the stopwatch code above, and what you'd like is to include it on a page but to have it start once the page has loaded instead of having the user click the start button? Is that right?
Also you say that it's not working, do you mean that you can't get it to start automatically or that the stopwatch code above is not working as you expect it to. If it's not working as you expect it to, is it working at all, if it is partly working what needs to be fixed in your estimation?