Results 1 to 2 of 2

Thread: Need help with a simple java script

  1. #1
    Join Date
    Sep 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Need help with a simple java script

    I'm a total n00b with java scripts but I need one for mt personal site.Namely,it's a script that changes an image 4 times a year,this is the script I need help with:

    <script language="JavaScript">

    var pics=new Array();
    pics[0]="images/ winter.gif";
    pics[1]="images/ spring.gif";
    pics[2]="images/ summer.gif";
    pics[3]="images/ fall.gif";

    var UW_Date=new Date();
    var d=UW_Date.getDate();
    var m=UW_Date.getMonth()+1;
    var s;

    if(m>1&&m<=3)s=0;
    else if(m==3&&d>19)s=1;
    else if(m>3&&m<=6)s=1;
    else if(m==6&&d>20)s=2;
    else if(m>6&&m<=9)s=2;
    else if(m==9&&d>21)s=3;
    else if(m>9&&m<=12)s=3;
    else if(m==12&&d>20)s=0;


    document.write('<img src="' + pics[s] + '">');

    </script>
    *BOLD - I know that these are the dates that define when the image changes but I don't really get what is what here.If anyone could help me with,if I for example needed the scripts to change the images on the following dates:

    September 5th
    October 6th
    November 8th
    Decemberr 9th

    Thanks in advance

  2. #2
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Seasonal Rotating Image script

    Thanks! You saved my butt. Thought I could repay. I modified your script (very little), tested it, and found this works.

    I defined the four seasons like this:

    Spring= 3/20 - 5/15
    Summer= 5/16 - 9/4
    Autumn= 9/5 - 11/23
    Winter= 11/24 - 3/19

    You'll likely want to change the names and directory locations of the seasonal pictures.

    I've been wanting to have more 'relevant' graphics on my site that rotate. I've been attempting without success. Thanks to you - I now have it.

    =====cut=====cut=====cut=====cut=====cut=====cut=====cut=====

    <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>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •