Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Image change every week

    Can anyone link me to code that will change an image everyweek to an image that I define? I have 52 different images, one for every week.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,906
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Try this:-

    Code:
    <div id = "myimagediv"><img src = "One.gif" id = "myimage"></div>
    
    <script type = "text/javascript">
    Date.prototype.getWeek = function() {
    var onejan = new Date(this.getFullYear(),0,1);  // month 0 is January
    return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
    } 
    
    var today = new Date();
    var weekno = today.getWeek(); 
    
    var images = []
    images [1] = "One.gif";
    images [2] = "Two.gif"
    images [3] = "Three.gif";
    images [4] = "Four.gif";
    images [5] = "Five.gif";
    // and so on for 53 weeks
    
    document.getElementById("myimage").src = images[weekno];
    
    </script>
    
    </body>
    </html>
    This is based on the week in which January 1st falls as being Week 1, though not all of the days in that week are necessarily in the current year. A week is defined as running from Sunday - Saturday. There are of course 53 weeks in a year (week 53 being fewer than 7 days).

    Did we not cover this in http://www.codingforums.com/showthread.php?p=891494?


    "I have never taken any exercise except sleeping and resting." - Mark Twain, US humorist, novelist, short story author, & wit (1835 - 1910)
    Last edited by Philip M; 12-03-2009 at 05:52 PM.

  • Users who have thanked Philip M for this post:

    jeremyp (12-03-2009)

  • #3
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Philip, yes we did, but before I asked for text also. Turns out they made 52 different images for each week. Thanks again for your help, I'll see how it works out.


  •  

    Posting Permissions

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