-
Help needed with "Seasonal Rotating pic"
All,
Problem resolved with the following code.
I specified the following date ranges for the seasons
Spring= 3/20 - 5/15
Summer= 5/16 - 9/4
Autumn= 9/5 - 11/23
Winter= 11/24 - 3/19
Note the names of the seasonal pictures must be changed.
==============================================================
<script language="JavaScript">
var pics=new Array();
pics[0]="/images/seasons/winter.jpg";
pics[1]="/images/seasons/spring.jpg";
pics[2]="/images/seasons/summer.jpg";
pics[3]="/images/seasons/autumn.jpg";
var UW_Date=new Date();
var d=UW_Date.getDate();
var m=UW_Date.getMonth()+1;
var s;
if(m>0&&m<=3)s=0;
if(m==3&&d>19)s=1;
if(m>3&&m<=6)s=1;
if(m==5&&d>15)s=2;
if(m>6&&m<=9)s=2;
if(m==9&&d>=5)s=3;
if(m>9&&m<=11)s=3;
if(m>11&&m<=13)s=0;
if(m==11&&d>23)s=0;
document.write('<img src="' + pics[s] + '">');
</script>
--------------------------------------
I'm a newbie with Javascript authoring. I need some help. My goal with the following script is to present differing images (not a background) based on the day (or season) of the year.
I feel the following is "close" - but no cigar! Maybe someone else's solution is better. If so - I welcome the chance to see. Can any of you with greater skill than I review and comment on the following? Thanks.
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--hide from old browsers
function setSeason()
{
if(document.images)
{
var today = new Date();
var month = today.getMonth();
var day = today.getDate();
var season;
if((month>0)&&(day>1)) season='/images/seasons/winter.jpg';
if((month>=3)&&(day>21)) season='/images/seasons/spring.jpg';
if((month>=5)&&(day>16)) season = '/images/seasons/summer.jpg';
if ((month>=9)&&(day>7)) season = '/images/seasons/autumn.jpg';
if (((month>=11)&&(day<22)) season = '/images/seasons/winter.jpg';
document.getElementById('season').src = season;
}
}
//end hide-->
</script>
</head>
<body onload="setSeason()">
<img name="season" src="javascript:image.jpg" width="200" height="200">
</body>
</html>
Last edited by kishbaugh; 09-07-2006 at 07:55 PM.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks