JavaScript | Very Neat!

Discussion in 'Web Programming' started by runescapepkz, Jun 4, 2007.

JavaScript | Very Neat!
  1. Unread #1 - Jun 4, 2007 at 10:51 PM
  2. runescapepkz
    Joined:
    May 20, 2007
    Posts:
    156
    Referrals:
    0
    Sythe Gold:
    0

    runescapepkz Active Member

    JavaScript | Very Neat!

    This is a simple stopwatch script. It has the standard Start, Stop and Reset functions.

    Code:
    <script language="JavaScript" type="text/javascript">
    \
    
    <!--
    var sec = -1;
    var min = 0;
    var hour = 0;
    function stopwatch(text) {
       sec++;
      if (sec == 60) {
       sec = 0;
       min = 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);
       sec=sec-1;
       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);
     }
    // -->
    </script>
    
    <!-- This goes into the BODY of the file -->
    
    <table bgcolor="#c0c0c0" align="center" border="0" width="140" cellspacing="0">
      <tr>
         <td align="center">
           <font face="verdana, arial, helvetica, sans-serif" size="2">
           <b>STOPWATCH</b></font>
         </td>
      </tr>
      <tr>
         <td align="center">
           <form name="clock">
           <input type="text" size="12" name="stwa" /><br />
           <input type="button" name="theButton" onClick="stopwatch(this.value);" value="Start" />
           <input type="button" value="Reset" onClick="resetIt();reset();" />
           </form>
         </td>
      </tr>     
    </table>

    Hope You Liked It Was A Simple Process.
     
  3. Unread #2 - Jun 6, 2007 at 3:43 PM
  4. Pimpinballa
    Joined:
    Apr 28, 2007
    Posts:
    915
    Referrals:
    0
    Sythe Gold:
    0

    Pimpinballa The Magician
    Banned

    JavaScript | Very Neat!

    Pretty nice. Keep it up.
     
< Selling Eliteclient Delphi source code | Help with Dreamweaver/HTML/java script please. >

Users viewing this thread
1 guest


 
 
Adblock breaks this site