...

View Full Version : display different image each day of the month



jockm
11-09-2006, 10:53 AM
I have a random image generator on my web site at

http://www.bridgeaholics.com

The random image is loaded from potshots.html by clicking on TODAY'S POTSHOT at the bottom of the home page.

This javascript is working satisfactorily, but having written it, I find its not quite what I want. What I really want is a different potshot to come up each day of the month. I have 31 potshots, so this should be no problem. What I would like to do is to test what day in the month it is, and then select that array element. For instance, today is wednesday Nov 9, so clicking TODAYS POTSHOT should bring up element [9]. Tomorrow, the same click sequence will bring up element [10] and so forth.

How do I find the numeric value of the day of the month? And then having found it use that as the array index value?

Bill Posters
11-09-2006, 11:12 AM
http://www.w3schools.com/jsref/jsref_getDate.asp

If you're using js, then be sure to implement a default img and use js to switch the src of that img to the correct one for that day of the month.

(rough) e.g.

var srcImg = document.getElementById('dailyImg');
var d = new Date();
var monthDay = d.getDate();
srcImg.src = monthDay + '.jpg';

A more robust approach might be to use PHP which would do the job even when the user doesn't have js enabled.

http://uk.php.net/manual/en/function.date.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum