topical media & game development

talk show tell print

game-javascript-casual-stopwatch-count-down.htm / htm



  
  <!-- ONE STEP TO INSTALL COUNT DOWN:
  
     1.  Copy the last code into the HEAD of your HTML document  -->
     2.  Put the last coding into the BODY of your HTML document  -->
  
  <!-- STEP ONE: Add this code into the HEAD of your HTML document  --> 
  
  <HEAD>
  
  <SCRIPT LANGUAGE="JavaScript">
  <!-- Hide the script from old browsers --
  <!-- Original:  Michael P. Scholtis (mpscho@planetx.bloomu.edu)
  
  <!-- This script and many more are available free online at -->
  <!-- The JavaScript Source!! http://javascript.internet.com -->
  
  <!-- Begin
  var up,down;
  var min1,sec1;
  var cmin1,csec1,cmin2,csec2;
  function Minutes(data) {
  for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;
  return(data.substring(0,i)); }
  function Seconds(data) {
  for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;
  return(data.substring(i+1,data.length)); }
  function Display(min,sec) {
  var disp;
  if(min<=9) disp=" 0";
  else disp=" ";
  disp+=min+":";
  if(sec<=9) disp+="0"+sec;
  else disp+=sec;
  return(disp); }
  function Up() {
  cmin1=0;
  csec1=0;
  min1=0+Minutes(document.sw.beg1.value);
  sec1=0+Seconds(document.sw.beg1.value);
  UpRepeat(); }
  function UpRepeat() {
  csec1++;
  if(csec1==60) { csec1=0; cmin1++; }
  document.sw.disp1.value=Display(cmin1,csec1);
  if((cmin1==min1)&&(csec1==sec1)) alert("Timer-CountUp Stopped");
  else up=setTimeout("UpRepeat()",1000); }
  function Down() {
  cmin2=1*Minutes(document.sw.beg2.value);
  csec2=0+Seconds(document.sw.beg2.value);
  DownRepeat(); }
  function DownRepeat() {
  csec2--;
  if(csec2==-1) { csec2=59; cmin2--; }
  document.sw.disp2.value=Display(cmin2,csec2);
  if((cmin2==0)&&(csec2==0)) alert("Timer-CountDown Stopped");
  else down=setTimeout("DownRepeat()",1000); }
  // End -->
  </SCRIPT>
  
  <!-- STEP TWO: Add this code into the BODY of your HTML document  --> 
  
  <BODY>
  
  <CENTER>
  <FORM name="sw">
  <TABLE border="3" width="100%">
  <TR><TH colspan="2">Timer-CountDown</TH></TR>
  <TR align="center"><TD>Start at<BR><input type="text" name="beg2" size="7" value="0:10"></TD>
  <TD><input type="button" value="Start" onclick="Down()"></TD></TR>
  <TR align="center"><td colspan="2"><input type="text" name="disp2" size="9"></TD></TR>
  </TABLE>
  </FORM>
  </CENTER>
  
  <p><center>
  <font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
  by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
  </center><p>
  
  <!-- Script Size:  2.21 KB  -->
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.