By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,627 Members | 1,870 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,627 IT Pros & Developers. It's quick & easy.

Javascript Dynamic Greeting and using Switch

P: 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
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
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.