473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 1801
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

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

Similar topics

2
by: Sam | last post by:
Hello everyone, I have a table, which contains a picture column, I put URL info into it. "www.myweb.com/1.jpg..." I want to show this picture in my crystal report, I find some samples show the...
2
by: Jens Körte | last post by:
Hi! I've got a typical newbie-problem, I guess. I got some selectboxes on my site. these boxes get their data from a databse. everything works fine, but when a user selects a value from one of...
6
by: bonehead | last post by:
Greetings, I'm working on an e-mail form (btw many thanks to Philip Ronan for the very cool email address format tester function, best I've seen so far). I've been trying, with limited...
4
by: Leon | last post by:
I have 10 .aspx pages within my web application and would like to know what is the best way I can write code within my header user control so that the greeting message change for each page the user...
5
by: Angel | last post by:
Is there any code out there that explains how to perform a connection to a SQL Database and returning a Dataset using Javascript. Unfortunately all the examples on MSDN are C++, C#, and VB.NET. ...
4
by: Zark3 | last post by:
Hi all, I was wondering if anybody could enlighten me on the possibility of dynamic casting. Or, well, whether or not I'm actually trying to do this the right way. What I have is a base class...
3
by: Cylix | last post by:
I have a function to validate the form I created: ------------------------------------------------------------------------------------------------------------------------------------ function...
6
by: William Pierce | last post by:
Hi, I have an interesting problem that I am stuck on and was wondering if there might be others who can shed some light.... Basically, within an HTML page, I have a tag that looks as...
2
by: linda.chen | last post by:
Greeting. We have a web service which is written in ASP.net (C#). When a user makes a request, it takes a while (average 100 seconds) to get the response. One of our users has dynamic IP...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.