Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    greeting messages that change w/date of year

    How can i create a greeting message (or does anyone know a template code for it) that will appear on my website as the webpage loads (because i don't want a visible calender where clicking on the date is necessary) that changes throughout the year? say:

    - from June 1 to Aug 30 i want a count down message saying "only X days of vacation left"
    - then on Sept 1 the message automatically becomes "School starts",
    - then between Sept 2 and Dec 20 it will read "Still in School"

    THANKS!!! x100

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Code:
    <script>
    	var today = new Date();
    
    	var vacationStart = new Date("1 Jun "+today.getFullYear());
    	var vacationEnd = new Date("30 Aug"+today.getFullYear());
    
    	if( today >= vacationStart && today <= vacationEnd ) {
    		var daysToGo = (Date.parse(vacationEnd)-Date.parse(today))/1000/60/60/24;
    		document.write("Only "+daysToGo+" day"+((daysToGo==1) ? "" : "s")+" of vacation left");
    	}
    	else if( today.getDate() == 1 && today.getMonth() == 8 ) 
    		document.write("School starts");
    	else if( today >= Date("2 Sept "+today.getFullYear()) && today <= Date("20 Dec"+today.getFullYear()) ) 
    		document.write("Still in school =(");
    </script>
    Simply copy and paste the whole thing into your web page where you want it to appear. If the date is outside the ones you have mentioned, nothing is written.

    Hope this helps!

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    Banned
    Join Date
    May 2005
    Location
    Midwest, U.S.
    Posts
    118
    Thanks
    1
    Thanked 26 Times in 23 Posts
    Seasonal text with countdown...
    Code:
    <HTML>
    <Head>
    <Script Language=JavaScript>
    
    	Message = new Object()
    	Message.Valentine = "Valentine\'sDay<br>Make it a special day for your Baby!";
    	Message.Memorial = "Memorial Day<br>...Remembering those in uniform who gave their lives for our freedom.";
    	Message.JulyFourth = "Independence Day<br>Happy 4th of July!";
    	Message.Halloween = "Halloween<br>Visit Spook City.";
    	Message.Christmas = "Christmas<br>Merry Christmas from our family to yours";
    	Message.NewYear = "New Year\'s Day<br>Happy New Year.";
    
    	dispDays = new Object()
    	dispDays.Valentine = "1/5|2/14";
    	dispDays.Memorial = "5/23|5/30";  
    	dispDays.JulyFourth = "6/10|7/10";
    	dispDays.Halloween = "10/10|10/31";
    	dispDays.Christmas = "11/28|12/25";
    	dispDays.NewYear = "12/26|12/31";
    
    	var refDate = 0;
    	var isYear = 0;
    	var Msgs = new Array();
    	var isHoliday = new Array();
    	var startDate = new Array();
    	var endDate = new Array();
    	var i = 0;
    
    	for (each in dispDays){dispDays[each] = dispDays[each].split("|")};
    	i = 0;
    	for (each in Message){Msgs[i++] = Message[each]}
    		
    	function selectMessage(){
    
    		i = 0;
    		for (each in dispDays){startDate[i++] = new Date(dispDays[each][0]+"/"+isYear)}
    		i =0;
    		for (each in dispDays){endDate[i++] = new Date(dispDays[each][1]+"/"+isYear)}
    		for (i=0; i<startDate.length; i++)
    			{if (refDate >= startDate[i] && refDate <= endDate[i])
    				{
    				 daysUntil = Math.round((endDate[i]-refDate)/86400000);
    				 MsgText = daysUntil+" Days until "+Msgs[i];
    				 document.getElementById('Msg').innerHTML = MsgText;
    				}
    			}
    	}
    
    	function getToday(){
    
    		refDate = new Date();
    		refDate.setHours(0,0,0,0);
    		isYear = refDate.getFullYear();
    		selectMessage();
    	}
    
    	window.onload=getToday;
    
    </Script>
    </Head>
    <Body>
    <Div id='Msg' style='width:325px;font-size:14pt;color:midnightblue;background-color:moccasin;border:solid black 1px;padding:5px;margin:10px;text-align:center'>Default Text</Div>
    </Body>
    </HTML>

  • #4
    New to the CF scene
    Join Date
    May 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for all the help!!! much appreciated!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •