Download JavaScript Code Examples, Tutorials, Reference

Provide thousands of free JavaScript code examples, DHTML, HTML JavaScript Tutorials, Reference and Help. JavaScriptBank.com is the best JavaScript resources




Over 2000+ free Javascript
at JavaScriptBank.com Website

Sampled by JavaScriptBank.com

Time Keeper

Big Money Project

Elapsed

Class TimeKeeper

function TimeKeeper() {  // Object Constructor
  // Properties
  this.enable = false;
  this.elapsed = 0;
  this.form = null;
  this.begin = null;
  // Methods
  this.start = function() {
    if (!this.enable) {
      this.begin = new Date();
      if (!this.elapsed) {
        this.form.txtHistory.value +=
          "Begin Session..." + "\n";
      }
      this.form.txtHistory.value +=
        "Start: " + this.begin.toLocaleString() + "\n";
      this.enable = true;
    }
  }
  this.stop = function() {
    if (this.enable) {
      this.enable = false;
      var dt = new Date();
      this.elapsed += dt - this.begin;
      this.form.txtHistory.value +=
        "Stop: " + dt.toLocaleString() + "\n";
      this.form.txtHistory.value +=
        "Elapsed: " + ms2hms(this.elapsed) + "\n";
      this.form.txtElapsed.value = ms2hms(this.elapsed);
    }
  }
  this.reset = function() {
    this.stop();
    if (this.elapsed != 0 || this.begin != null) {
      this.elapsed = 0;
      this.begin = null;
      this.form.txtHistory.value +=
        "...End Session" + "\n\n";
    }
  }
}
  

TimeKeeper Instantiation

To create a TimeKeeper object call the function createTimeKeeper() within the Body element. The following shows how the TimeKeepers on this page were created. This Script element must be placed in the Body element of the page.

<script type="text/javascript">
  createTimeKeeper("Big Money Project");
  createTimeKeeper("Little Money Project");
</script>