473,549 Members | 2,753 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript Dynamic Greeting and using Switch

10 New Member
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...Thank s!

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <TITLE>Midwest Catering Service</TITLE>
  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.          }          
  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>
  64. <!--  Hide from old browsers
  65.       var holidayMsg = HolidayDays()
  66.       document.write("<H2><CENTER>"+holidayMsg+"</CENTER></H2>")
  68. //-->
  69. </SCRIPT>
  70. </BODY>
  71. </HTML>
Jan 23 '09 #1
1 1814
16,027 Recognized Expert Moderator MVP
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

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 "static" picture in Crystal report, No "Dynamic" one. Can Crystal Report do that? Thanks in advance. Sam
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 the boxes i want to change the values from the other boxes dynamically. The values are derived from the database. Initially the boxes get for...
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 success, to produce a javascript alert box which shows the user a validation error message. The error message itself is dynamic, i.e., it's contained...
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 are currently viewing ("should I do an if/else or case statement within my header user control?")? how? Also what is the best way to know...
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. I'd like to perform certain functions on the client without having to send the entire page to the server... thanks
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 that several classes inherit from. From time to time I need to add new inherited types so I want something that is as versatile as possible,...
by: Cylix | last post by:
I have a function to validate the form I created: ------------------------------------------------------------------------------------------------------------------------------------ function frmValidation(frm) { var elems = document.forms.elements; var i,rtn=true; for (i=0;i<elems.length;i++) { if (elems.type=='checkbox') { if...
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 follows: <div id="xxx"> </div>
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 address. He is complaining that he does not get the response back. When I checked our log file from the server, I can see the whole process had been...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.