Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6376599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:45:58+00:00 2026-05-25T01:45:58+00:00

I found this stopwatch javascript, complete with Start, Stop and Reset buttons. The functionality

  • 0

I found this stopwatch javascript, complete with “Start”, “Stop” and “Reset” buttons. The functionality of this script is great, but I would like to spruce it up a bit. I’ve managed to style the button background with CSS border-image, but I want to use javascript to replace the “Start”, “Stop” and “Reset” text with icons.

I would also like to make the timer start when the user clicks on another area. For example, I may use this to track how long a user takes to solve a puzzle…so it would be great if the “Start” button could be activated upon the user’s FIRST event recorded on the puzzle. I though about making an event listener for any click, but I’m afraid that may cause the button to toggle Start/Stop on each event.

Lastly, it would be nice if the “Stop” button triggered a hidden div with a message screen that shows up on top of the puzzle while the game is paused. Below is a snippet of my code

JAVASCRIPT

var sec = 0;
var min = 0;
var hour = 0;
function stopwatch(text) {
sec++;
if (sec == 60) {
sec = 0;
 = min + 1; }
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);
alert("Timer is Paused...Resume?");
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);
}

CSS

.button {
border-width:0 5px; -webkit-border-image:url(../images/toolButton-791569.png) 0 5 0 5;   padding:7px 0; font: bold 12px Arial,sans-serif; color:#fff; width:auto; margin:5px 10px 0 0; width:auto; height: 25px; text-align:center; cursor:pointer;
}

HTML

   <div id="timer">
   <form name="clock">
   <input type="text" size="14" name="stwa" value="00 : 00 : 00" style="text-align:center; position: relative; top: 0px; background: #ccc; font-weight: bold; font-size: 14px;" />
   <br/><input type="button" class="button" name="theButton" onClick="stopwatch(this.value);" value="Start" />
   <input type="button" class="button" value="Reset" onClick="resetIt();reset();" />
   </form></div>

I’m sure the brilliant programmers in this community might find this question to be trivial, but please forgive me. I am a novice programmer and this challenge is causing me many sleepless nights. Please help…

Thanks,
Carlos

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:45:59+00:00Added an answer on May 25, 2026 at 1:45 am

    Here you go http://jsfiddle.net/mplungjan/C4wjV/

    I did not do the pause button

    <style type="text/css">
    img { height:50px }
    #stwa {text-align:center; position: relative; top: 0px; background: #ccc; font-weight: bold; font-size: 14px;}
    </style>
    
    <script type="text/javascript">
    var buttons = {
        Start:"http://morethanvoice.net/m1/img/play.gif",
        Stop:"http://morethanvoice.net/m1/img/pause.gif"
    }
    var sec = 0,min = 0,hour = 0,SD;
    
    function stopwatch(text) {
      sec++;
      if (sec === 60) {
        sec = 0;
        min += 1;
      }
      if (min === 60) {
        min = 0;
        hour += 1;
      }
    
      document.clock.stwa.value = ((hour<10) ? "0"+hour : hour) + " : " +
            ((min<10) ? "0" + min : min) + " : " +
            ((sec<10)? "0" + sec:sec);
    
      if (text) { // i.e. we are clicked
        if (text==="Stop") window.clearTimeout(SD);
        text = (text==="Start")?"Stop":"Start";
        document.getElementById('stopstart').title=text;
        document.getElementById('stopstarticon').src=buttons[text];  
      }
        if (!text || text === "Stop") SD=window.setTimeout(function() {stopwatch()}, 1000);
      return false;
    }
    
    function resetIt() {
      sec = -1;
      min = 0;
      hour = 0;
      document.getElementById('stopstart').title = "Start"
      document.getElementById('stopstarticon').src=buttons["Start"];
      window.clearTimeout(SD);
      document.clock.stwa.value=document.clock.stwa.defaultValue;
      return false;
    }
    </script>
    
        <form name="clock"><input type="text" size="14" id="stwa" name="stwa" value="00 : 00 : 00"  />
    </form><br/>
    
    <a href="#" id="stopstart" title="Start"
    onClick="return stopwatch(this.title)"><img id="stopstarticon" src="http://morethanvoice.net/m1/img/play.gif" border="0" /></a>
    <a href="#" onClick="return resetIt()"><img src="http://morethanvoice.net/m1/img/rewind.gif" border="0" /></a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Found this Reboot Vista.vbs script on a number of forums. Seems like the whole
I found this question, which is similar to a problem that I would like
Found this: Sub SurroundWithAppendTag() DTE.ActiveDocument.Selection.Text = .Append( + DTE.ActiveDocument.Selection.Text + ) End Sub But
I found this link http://artis.imag.fr/~Xavier.Decoret/resources/glsl-mode/ , but there isn't a lot of description around
I found this in an article on Multithreaded Apartments, but can’t find a definition
I found this PECL package called threads , but there is not a release
found this puzzle HERE ... I made a brute force solution and I would
Found this at MDC but how if I'd wanted to add a private variable
Found this script: function stopRKey(evt) { var evt = (evt) ? evt : ((event)
I found this great example which takes an sql statement and dynamically adds the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.