...

View Full Version : greeting messages that change w/date of year



kikilala
05-23-2005, 07:55 AM
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!!! :confused: x100

martin_narg
05-23-2005, 02:18 PM
<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

Cranford
05-23-2005, 07:17 PM
Seasonal text with countdown...


<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>

kikilala
05-23-2005, 11:33 PM
Thanks for all the help!!! much appreciated!!! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum