jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Need Event Timer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need Event Timer" Watch "Need Event Timer" New topic

Need Event Timer

Charles Wood

Joined: Jun 15, 2006
Posts: 4
Hello All,

I need to time an unlimited number of events, in seconds, by a succession of key presses. The end of one event is the beginning of the next event.

I found this code, which gets me part way there. But it does not give me the time of each event and requires a mouse-click of a button, rather than pressing a key.

Could someone suggest the modifications that must be made?

<script type="text/javascript">
var startTime;
function doTime(a, x){
var x = document.getElementById(x);
if ( 'start' == a) {
startTime = new Date();
x.innerHTML = 'Delay in seconds: 0';
} else {
var t = new Date().getTime() - startTime.getTime();
x.innerHTML += '<br>click: ' + t/1000;
<input type="button" value="Start..." onklick="
<input type="button" value="Click me..." onklick="
<br><span id="x"></span>

This function was easy for this Senior Citizen quite a few years back when I was using BASIC.

Thanks for any help.

[ June 15, 2006: Message edited by: Charles Wood ]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
BASIC, eh? Well, what you have here is JavaScript and this forum is for Java, an unrelated language. Perhaps you meant to go here:


There is no emoticon for what I am feeling!
Charles Wood

Joined: Jun 15, 2006
Posts: 4
Hi Jeff,

Thanks for the reply directing me to the right place. Shows how much help I need.

I'll try again at the forum you suggested.

Charles Wood
I agree. Here's the link: http://aspose.com/file-tools
subject: Need Event Timer
It's not a secret anymore!