Solved

Javascript stopwatch

Posted on 2011-03-04
2
456 Views
Last Modified: 2012-05-11
Hey guys... im tryin to make alterations to my stopwatch but im stuck.

I want it to do this...

Show the time so at it just adds one but i want it to be in hh:mm.ss
I also would like to record time started and finished so:
04/03/11 11:49 - 12:00

so records the data and time it started and time it stopped so the outcome will be:


04/03/11 11:49 - 12:00    00:12.23


below is my current code
<html>
<head>
<script type="text/javascript">
var c=0;
var t;
var timer_is_on=0;
var x=1;


function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000);
}

function doTimer()
{
if (!timer_is_on)
  {
  timer_is_on=1;
  timedCount();
  }
}

function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}

function saveSeconds()
{
   var seconds = document.getElementById('txt').value;
   if (!timer_is_on && seconds != '')
   {
        document.getElementById('save').value = document.getElementById('save').value + x++ + ":" + seconds + '\n';
        c=0;
        document.getElementById('txt').value = '';
   }
}



</script>
</head>

<body>
<form>
<input type="button" value="Start count!" onClick="doTimer()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCount()">
<input type="button" value="Save" onClick="saveSeconds()">
<br>
<textarea id="save" name="save" cols="10" rows="10"></textarea>
</form>
</body>
</html>I have another question but will go in a new thread!

Cheers! and thanks for the welcoming

Open in new window

0
Comment
Question by:runnerjp2005
2 Comments
 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 35035458
look this link

http://www.sivamdesign.com/scripts/clocks.html

hopes its helps u!!!!!
0
 
LVL 9

Accepted Solution

by:
jkofte earned 500 total points
ID: 35035668
I also include

var currentHours = currentTime.getHours();
var currentMinutes = currentTime.getMinutes();
var currentSeconds = currentTime.getSeconds();

so that you may display them if you need to.

<html>
<head>
<script type="text/javascript">
var c=0;
var t;
var timer_is_on=0;
var x=1;


function timedCount()
{
var currentTime = new Date();
var currentHours = currentTime.getHours();
var currentMinutes = currentTime.getMinutes();
var currentSeconds = currentTime.getSeconds();
document.getElementById('txt').value=currentTime;
t=setTimeout("timedCount()",1000);
}

function doTimer()
{
if (!timer_is_on)
  {
  timer_is_on=1;
  timedCount();
  }
}

function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}

function saveSeconds()
{
   var seconds = document.getElementById('txt').value;
   if (!timer_is_on && seconds != '')
   {
        document.getElementById('save').value = document.getElementById('save').value + x++ + ":" + seconds + '\n';
        c=0;
        document.getElementById('txt').value = '';
   }
}



</script>
</head>

<body>
<form>
<input type="button" value="Start count!" onClick="doTimer()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCount()">
<input type="button" value="Save" onClick="saveSeconds()">
<br>
<textarea id="save" name="save" cols="10" rows="10"></textarea>
</form>
</body>
</html>I have another question but will go in a new thread!

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
crm development 2 37
creating a flowchart from an algorithm 5 21
ASP.Net Session State alternatives 3 28
JavaScript error 1 33
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

706 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

18 Experts available now in Live!

Get 1:1 Help Now