[Javascript] Newbie- Switch Statement Problem

Steve extstarrfam at cox-internet.com
Mon Mar 18 13:52:41 CST 2002


I submitted a problem concerning this code before.  I no longer receive an Error message.  However, when the program is opened the only display presented is the Default display.  There is something wrong with the Switch code or it is not appropriate to use it this way.  Will someone please help me understand my mistake.  This is just a personal learning project but is important to me.   Here is the code after the changes:

<head>
<script language="JavaScript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com
// Altered by S. K. Starr 11/18/02.
var pace = 0;

function UpdateClock() {
 if(pace) {
  clearTimeout(pace);
  pace  = 0;
 }

 var theDate = new Date();
 var secCtr = theDate.getSeconds();
 
 switch(secCtr) {
     case secCtr <= 2:
  document.theForm.textDisplay.value="";
  
     case secCtr > 2 && secCtr <= 5:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 5 && secCtr <= 7:
  document.theForm.textDisplay.value="";
  
     case secCtr > 7 && secCtr <= 10:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 10 && secCtr <= 12:
  document.theForm.textDisplay.value="";
  
     case secCtr > 12 && secCtr <= 15:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 15 && secCtr <= 17:
  document.theForm.textDisplay.value="";
  
     case secCtr > 17 && secCtr <= 20:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 20 && secCtr <= 22:
  document.theForm.textDisplay.value="";
  
     case secCtr > 22 && secCtr <= 25:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 25 && secCtr <= 27:
  document.theForm.textDisplay.value="";
  
     case secCtr > 27 && secCtr <= 30:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 30 && secCtr <= 33:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 33 && secCtr <= 35:
  document.theForm.textDisplay.value="";
  
     case secCtr > 35 && secCtr <= 38:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 38 && secCtr <= 40:
  document.theForm.textDisplay.value="";
  
     case secCtr > 40 && secCtr <= 43:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 43 && secCtr <= 45:
  document.theForm.textDisplay.value="";

     case secCtr > 45 && secCtr <= 48:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 48 && secCtr <= 50:
  document.theForm.textDisplay.value="";
  
     case secCtr > 50 && secCtr <= 53:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 53 && secCtr <= 55:
  document.theForm.textDisplay.value="";
  
     case secCtr > 55 && secCtr <= 57:
  document.theForm.textDisplay.value = "READ THIS NOW";
  
     case secCtr > 57 && secCtr <= 59:
  document.theForm.textDisplay.value="";
  
     default:
  document.theForm.textDisplay.value="no display";
 }

 pace = setTimeout("UpdateClock()", 1000);
//document.write("CLOCK SECONDS  " + secCtr);
}

function startFlash() {
 pace = setTimeout("UpdateClock()", 500);
}

function stopFlash() {
 if(pace) {
  clearTimeout(pace);
  pace  = 0;
 }
}

//-->
</script>
</head>
<body onload="startFlash()" onunload="stopFlash()">
<form name="theForm">
<input type="text" name="textDisplay" length="12" style="font-size: x-large; text-align: center; background: #0000FF; color: #FFFFFF;">
</form>
</body>
</html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20020318/15b6d941/attachment.htm>


More information about the Javascript mailing list