Rotating banner - one image a day - 7 days a week

Website Tips

Sometimes I take part in the discussion on a few forums, one of which is facilitated by the Web Host where I have parked my website and a couple of blogs. One participant wanted to know if it was possible to have a script that will display a different image on each of the seven days of the week. It should then start again for the next week and so on. So then it would depend on the day of the week. She said she has seven images with given hyperlinks and the target must be set to _blank.

I came up with the following JavaScript with some notes for clarification of what I have done.You can tweak it to your liking. Obviously you have to change the images and URL. Target is set to _blank for all URLs per user's instructions. You can remove the document.writeln two statements if you want.

As you can see new date is picked up ONLY when the page is refreshed. Otherwise, you can bring it into the loop. However, that would be an overkill.

<script language="JavaScript" type="text/javascript">

var RotatingImage1_Images = new Array(1);
var RotatingImage1_URLs = new Array(1);
var RotatingImage1_Targets = new Array(1);
var weekday = new Array(1);

var RotatingImage1_Index = 1;

RotatingImage1_Targets[1] = "_blank";

var d=new Date();
var dnum=d.getDay();

switch (dnum)
{
case 0 :
RotatingImage1_Images[1] = "http://www.mywebsiteworkout.com/ad-rotator-bv.gif";
RotatingImage1_URLs[1] = "http://www.vodahost.com/partner/idevaffiliate.php?id=8418_1_1_69";
weekday[1]="Sunday";
break;

case 1 :
RotatingImage1_Images[1] = "http://www.mywebsiteworkout.com/ad-rotator-vh.gif";
RotatingImage1_URLs[1] = "http://www.vodahost.com/partner/idevaffiliate.php?id=8418_0_1_139";
weekday[1]="Monday";
break;

case 2 :
RotatingImage1_Images[1] = "http://www.mywebsiteworkout.com/ad-rotator-gp.gif";
RotatingImage1_URLs[1] = "http://www.vodahost.com/partner/idevaffiliate.php?id=8418_10_1_90";
weekday[1]="Tuesday";
break;

case 3 :
RotatingImage1_Images[1] = "http://www.mywebsiteworkout.com/ad-rotator-sb.gif";
RotatingImage1_URLs[1] = "http://www.seobook.com/3578-1-1-26.html";
weekday[1]="Wednesday";
break;

case 4 :
RotatingImage1_Images[1] = "http://www.mywebsiteworkout.com/ad-rotator-wc.gif";
RotatingImage1_URLs[1] = "http://www.webceo.com/cgi-bin/go/clickthru.cgi?id=wysiwyg4";
weekday[1]="Thursday";
break;

case 5 :
RotatingImage1_Images[1] = "http://www.mywebsiteworkout.com/ad-rotator-bv.gif";
RotatingImage1_URLs[1] = "http://www.vodahost.com/partner/idevaffiliate.php?id=8418_1_1_69";
weekday[1]="Friday";
break;

default :
RotatingImage1_Images[1] = "http://www.mywebsiteworkout.com/ad-rotator-vh.gif";
RotatingImage1_URLs[1] = "http://www.vodahost.com/partner/idevaffiliate.php?id=8418_0_1_139";
weekday[1]="Saturday";
}

function RotatingImage1ShowNext()
{
eval("document.RotatingImage1.src = RotatingImage1_Images[" + RotatingImage1_Index + "]");
RotatingImage1ShowNext();
}

function onRotatingImage1Click()
{
targetwin = RotatingImage1_Targets[RotatingImage1_Index];
eval("window.open(url = RotatingImage1_URLs[RotatingImage1_Index],'" + targetwin +"');");
}

document.writeln("<PRE>Image for " + weekday[1]);
document.writeln("</PRE>");

</script>
<a href="#" onClick="onRotatingImage1Click();return false;">
<img src="http://www.mywebsiteworkout.com/ad-rotator-bv.gif" id="RotatingImage1" border="0" align="top" width="468" height="60" name="RotatingImage1"></a>

<script language="JavaScript" type="text/javascript">
RotatingImage1ShowNext();
</script>