...

View Full Version : how do I change an image depending on which month it is?



billytalent
10-12-2003, 07:44 PM
using the get.date function in javascript, how can I retrieve the month, and then use this information to display a month-dependant image (ie if the month is october, then the image will be unique to october and only be shown in october)
I suppose it is a bit like a calendar that knows which displays the current month as that is of most use, but I'm using images instead, does anyone know how I may achieve this?

every help appreciated,
thanks!

COBOLdinosaur
10-12-2003, 08:25 PM
Just create a series of images named month0.jpg through month11.jpg thn:


<html>
<head>
<title> monthly image</title>
<script language="JavaScript">
<!--
function setimage()
{
var thedate=new Date();
var nmonth=thetime.getMonth();
var str='month'+nmonth+'.jpg';
document.images['monthimage'].src=str;
}
</script>
</head>
<body onLoad="setimage()">
<img name="monthimage" src="">
The rest of the page
</body>
</html>

billytalent
10-12-2003, 08:54 PM
hi COBOLdinosaur!

that code looked perfect, so i made the page, made the images, and the only part of the code I changed was .jpg to .gif, the page is coming back with an error though, and I cant figure out what is wrong!

here's (http://www.thatmiltonkeynesband.co.uk/monthly) the page i made,

thankyou for your time :)

nolachrymose
10-12-2003, 09:05 PM
Looks like you got a little pseudo-variable in your head (:P):


var thedate = new Date();
var nmonth = thetime.getMonth();

...ought to be:


var thedate=new Date();
var nmonth=thedate.getMonth();

Hope that helps!

Happy coding! :)

billytalent
10-12-2003, 09:11 PM
thankyou both so much, hehe well I'm a bit stupid for missing that bit of code :)

thanks:thumbsup:

christophe
10-14-2003, 08:28 PM
Dear all,

I also would like to use this code, but I have some problems if I want to
use the function for multiple images, also can I not pass the image to an popup function

<html>
<head>
<title> day of weekimage</title>

<script language="JavaScript1.2">
function setimage()
{
var thedate=new Date();
var ndayofweek=thedate.getUTCDay();
var strthumb='thumbnails/verbouwing_'+ndayofweek+'_';
var strimage='images/verbouwing_'+ndayofweek+'_';

//fill in here every new picture
document.images['thumb20031013'].src=strthumb+'20031013'+'.jpg';
document.images['image20031013'].src=strimage+'20031013'+'.jpg';

document.images['thumb20031014'].src=strthumb+'20031014'+'.jpg';
document.images['image20031014'].src=strimage+'20031014'+'.jpg';
}
</script>
</head>

<body onLoad="setimage()">
<img class='photo' align='left' name='thumb20031013' src='' id='verbouwing_20031013' alt='klik om te vergroten...' onclick="imgPop(image20031013);" onload="fnNormalize(this);" onMouseOver="fnBlur(this);" onMouseOut="fnNormalize(this);">

<img class='photo' align='left' name='thumb20031014' src='' id='verbouwing_20031014' alt='klik om te vergroten...' onclick="imgPop(image20031014);" onload="fnNormalize(this);" onMouseOver="fnBlur(this);" onMouseOut="fnNormalize(this);">
</body>
</html>


greetings

christophe
10-14-2003, 09:05 PM
found it

I wanted to go to fast,

function setpopimage(myimage)
{
var thedate=new Date();
var ndayofweek=thedate.getUTCDay();
var strimage='images/verbouwing_'+ndayofweek+'_'+myimage+'.jpg';

imgPop(strimage);
}



<img class='photo' align='left' name='thumb20031014' src='' id='verbouwing_20031014' alt='klik om te vergroten...' onclick="setpopimage('20031014');" onload="fnNormalize(this);" onMouseOver="fnBlur(this);" onMouseOut="fnNormalize(this);">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum