471,851 Members | 859 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,851 software developers and data experts.

Javascript Dynamic Greeting and using Switch

10
Having a problem and have tried to rework the code and check for errors, but still isn't showing right on my brower. Have also viewed it with two different browsers and cannot figure this one out. Any help would be appreciated!

Under a rolling banner on the page...I want a dynamic greeting to show how many days until a given holiday. Right now the only thing showing is the statement "Leave the party to Midwest Catering" and nothing about days until the closest holiday...Thanks!

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <TITLE>Midwest Catering Service</TITLE>
  4. <SCRIPT LANGUAGE="JAVASCRIPT">
  5. <!--  Hide from old browsers
  6.      var banners = new Array("banner1.jpg","banner2.jpg","banner3.jpg","banner4.jpg")
  7.      var bnrCntr = 0
  8.      function bancycle() {
  9.           bnrCntr = bnrCntr + 1
  10.           if (bnrCntr == 4) {
  11.           bnrCntr = 0
  12.           }
  13.           document.Banner.src = banners[bnrCntr]
  14.           setTimeout("bancycle()",3000)
  15.      }
  16.      var holidayCntMsg = "Leave the party to Midwest Catering"
  17.      var curDay = new Date()
  18.      var tMonth = curDay.getMonth()
  19.      function HolidayDays() {
  20.      switch (tMonth) { 
  21.             case 2:
  22.                var tHoliday = new Date("March 17, 2009")
  23.                var curHoliday = tHoliday.getTime()-curDay.getTime()
  24.                if (curHoliday > 0) {
  25.                    curHoliday = Math.ceil(curHoliday / (1000 * 60 * 60 * 24))
  26.                    holidayCntMsg = "Only "+curHoliday+" days until St. Patrick's Day!"
  27.                }
  28.                break
  29.             case 5: case 6:
  30.                var tHoliday = new Date("July 4, 2009")
  31.                var curHoliday = tHoliday.getTime()-curDay.getTime()
  32.                if (curHoliday > 0) {
  33.                   curHoliday = Math.ceil(curHoliday / (1000 * 60 * 60 * 24))
  34.                   holidayCntMsg = "Only "+curHoliday+" days until the 4<SUP>th</SUP>of July!"
  35.                }
  36.                break
  37.             case 9:
  38.         var tHoliday = new Date("October 31, 2009")
  39.                var curHoliday = tHoliday.getTime()-curDay.getTime()
  40.                if (curHoliday > 0) {
  41.                   curHoliday = Math.ceil(curHoliday / (1000 * 60 * 60 * 24))
  42.                   holidayCntMsg = "Only "+curHoliday+" days until Halloween!"
  43.                }
  44.                break
  45.             case 11:
  46.                var tHoliday = new Date("December 25, 2009")
  47.                var curHoliday = tHoliday.getTime()-curDay.getTime()
  48.                if (curHoliday > 0) {
  49.                   curHoliday = Math.ceil(curHoliday / (1000 * 60 * 60 * 24))
  50.                   holidayCntMsg = "Only "+curHoliday+" days until Christmas!"
  51.                }
  52.                break
  53.             }
  54.          return holidayCntMsg
  55.          }          
  56.  
  57. //-->
  58. </SCRIPT>
  59. </HEAD>
  60. <BODY onload="setTimeout('bancycle()',3000)">
  61. <A NAME="MCS_TOP">
  62. <CENTER><IMG SRC="banner1.jpg" Name="Banner" Width=320 Height=65></CENTER>
  63. <SCRIPT LANGUAGE="JAVASCRIPT">
  64. <!--  Hide from old browsers
  65.       var holidayMsg = HolidayDays()
  66.       document.write("<H2><CENTER>"+holidayMsg+"</CENTER></H2>")
  67.  
  68. //-->
  69. </SCRIPT>
  70. </BODY>
  71. </HTML>
  72.  
Jan 23 '09 #1
1 1674
acoder
16,027 Expert Mod 8TB
It's not going to display anything until the date is set to one of the months.
Jan 26 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Jens Körte | last post: by
6 posts views Thread by bonehead | last post: by
4 posts views Thread by Leon | last post: by
5 posts views Thread by Angel | last post: by
4 posts views Thread by Zark3 | last post: by
3 posts views Thread by Cylix | last post: by
6 posts views Thread by William Pierce | last post: by
2 posts views Thread by linda.chen | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.