View Full Version : Help with Image Swap by Day

12-01-2005, 06:23 PM
okay. I have been searching from forums to sites and I have yet found a script that allows image swapping by actual day. Here is what I want to do:

On page load to see the day (ie Wednesday, Friday, Saturday) then load that day's image.

here's what I came up with - my C is very rusty and I know it sorta goes like this:

<SCRIPT language="JavaScript">
var wednesdayImage = 'Wednesday.gif';
var fridayImage = 'friday.gif';
var saturdayImage = 'saturday.gif';
var now = new Date();
var tday= new Array('Sunday','Sun','Monday','Mon', 'Tuesday','Tue', 'Wednesday','Wed','Thursday','Thr','Friday','Fri','Saturday','Sat');
if (tday >= Wednesday && tday <= Saturday)
document.write('<IMG SRC="' + wednesdayImage + '">');
document.write('<IMG SRC="' + fridayImage + '">');
document.write('<IMG SRC="' + saturdayImage + '">');

Am I wrong? help please.

12-01-2005, 07:39 PM
You're overcomplicating things. And what does C have to do with Javascript? They're fairly far removed :)

<script type="text/javascript">

// imgs is an array of images, from 0 (Sunday) to 6 (Saturday).
var imgs = new Array(),
today = new Date();
today = today.getDay();
imgs[3] = "Wednesday.gif";
imgs[5] = "friday.gif";
imgs[6] = "saturday.gif";
document.write("<img src=\"" + imgs[today] + "\"/>");