Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Newbie- Still having switch statement problems i n IE 5.5
- From: javascript@xxxxxxxxxx (Mckinney, Lori K)
- Subject: [Javascript] Newbie- Still having switch statement problems i n IE 5.5
- Date: Fri, 22 Mar 2002 08:31:44 -0600
Steve, It appears to me that the problem is your switch statement is switching on a number but all of your case values evaluate to a Boolean. So if the value of secCtr is 14 for example, the switch looks essentially like this: switch (14) case false: ... break; case false: ... break; case false: ... break; case false: ... break; case false: ... break; case true: ... break; etc } Since 14 does match in value and datatype true or false, it will always fall through to the default. I changed the switch(secCtr) to switch(true) and your code appeared to work for me on IE 5.5. Lori -----Original Message----- From: Steve [mailto:extstarrfam@xxxxxxxxxxxxxxxx] Sent: Thursday, March 21, 2002 5:17 PM To: javascript@xxxxxxxxxx Subject: [Javascript] Newbie- Still having switch statement problems in IE 5.5 I have tried to make the switch statement work with and without the break statement and with and without a default value. Is there a bug in IE 5.5 that will not allow this to work? If I use if statements instead of a switch statement, it work. I am not getting a syntax error message. Here is the code minus the HTML declaration: <head> <script language="JavaScript"> <!-- // please keep these lines on when you copy the source // made by: Nicolas // Altered by S. K. Starr 11/18/02. var pace = 0; function UpdateClock() { if(pace) { clearTimeout(pace); pace = 0; } // I could not get the seconds placed into a variable and // make it work. var theDate = new Date(); var secCtr = theDate.getSeconds(); // Flashing text display code starts here switch (secCtr) { case secCtr <= 2: document.theForm.textDisplay.value = ""; break; case secCtr > 2 && secCtr <= 5: document.theForm.textDisplay.value = "3 thru 5"; break; case secCtr > 5 && secCtr <= 7: document.theForm.textDisplay.value = ""; break; case secCtr > 7 && secCtr <= 10: document.theForm.textDisplay.value = "8 thru 10"; break; case secCtr > 10 && secCtr <= 12: document.theForm.textDisplay.value = ""; break; case secCtr > 12 && secCtr <= 15: document.theForm.textDisplay.value = "13 thru 15"; break; case secCtr > 15 && secCtr <= 17: document.theForm.textDisplay.value = ""; break; case secCtr > 17 && secCtr <= 20: document.theForm.textDisplay.value = "18 thru 20"; break; case secCtr > 20 && secCtr <= 22: document.theForm.textDisplay.value = ""; break; case secCtr > 22 && secCtr <= 25: document.theForm.textDisplay.value = "23 thru 25"; break; case secCtr > 25 && secCtr <= 27: document.theForm.textDisplay.value = ""; break; case secCtr > 27 && secCtr <= 30: document.theForm.textDisplay.value = "28 thru 30"; break; case secCtr > 30 && secCtr <= 32: document.theForm.textDisplay.value = ""; break; case secCtr > 32 && secCtr <= 35: document.theForm.textDisplay.value = "33 thru 35"; break; case secCtr > 35 && secCtr <= 37: document.theForm.textDisplay.value = ""; break; case secCtr > 37 && secCtr <= 40: document.theForm.textDisplay.value="38 thru 40"; break; case secCtr > 40 && secCtr <= 42: document.theForm.textDisplay.value = ""; break; case secCtr > 43 && secCtr <= 45: document.theForm.textDisplay.value=""; break; case secCtr > 45 && secCtr <= 48: document.theForm.textDisplay.value = "46 thru 48"; break; case secCtr > 48 && secCtr <= 50: document.theForm.textDisplay.value=""; break; case secCtr > 50 && secCtr <= 53: document.theForm.textDisplay.value = "51 thru 53"; break; case secCtr > 53 && secCtr <= 55: document.theForm.textDisplay.value=""; break; case secCtr > 55 && secCtr <= 58: document.theForm.textDisplay.value = "56 thru 58"; break; case secCtr > 58 && secCtr < 60: document.theForm.textDisplay.value=""; break; default: document.theForm.textDisplay.value=secCtr; } pace = setTimeout("UpdateClock()", 1000); } 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> _______________________________________________ Javascript mailing list Javascript@xxxxxxxxxx https://lists.LaTech.edu/mailman/listinfo/javascript
- Prev by Date: [Javascript] urgent business/investment deal
- Next by Date: [Javascript] How can search engines see a js include for navigation?
- Previous by thread: [Javascript] urgent business/investment deal
- Next by thread: [Javascript] How can search engines see a js include for navigation?
- Index(es):