• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Event Timer

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
}
</script>
<input type="button" value="Start..." onklick="
doTime('start','x');
">
<input type="button" value="Click me..." onklick="
doTime('blah','x');
">
<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.

Charles
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Search google for

JavaScript with any of these event handlers below:

onkeypress
or
onkeydown
or
onkeyup

Eric
 
Charles Wood
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,

Thanks for the tip ... I'll go take a look.

Charles Wood
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic