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
    Jan 2006
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto change image at certain date

    Is there a script anywhere that will change an image on my website at a set date/time?

    I have site that advertises a lot of fixtures, these are in a 220x160 banner form and I would like the image to change 2 or 3 times a week depending on what is coming up.

    Any ideas?

  • #2
    New Coder
    Join Date
    Oct 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you know JavaScript, here is the plan:
    1. Make an array of images.
    2. Get the current day of the month.
    3. For once a month: If the current date matches 20 (4/20,5/20...), for instance, then get the next array property; For twice a month: If the current date matches 10 elseif the current date matches 20 do stuff in both conditional clauses.

    Basically that.

    Shaffer.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,146
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    This is something I use and which changes to a different image each day
    for 2 weeks (14 images).

    <SCRIPT Language="JavaScript">
    <!--
    today = new Date();
    day = today.getDay();
    ddd = today.getDate();
    if (ddd %2 ==0) { // if date divisible by 2
    arday = new Array("ps36.jpg", "ps17.jpg", "ps40.jpg",
    "ps13.jpg", "ps16.jpg", "ps26.jpg", "ps18.jpg");
    document.write("<p align='center'><img src='" + arday[day] + "' width=271 height=168 border=0>");
    }

    else { // if date not divisible by 2
    arday = new Array("ps03.jpg", "ps35.jpg", "ps07.jpg",
    "ps27.jpg", "ps18.jpg", "ps30.jpg", "ps05.jpg");
    document.write("<p align='center'><img src='" + arday[day] + "' width=271 height=168 border=0>");
    }
    // -->
    </SCRIPT>

    You could easily modify this to suit your needs. For eample, to change the image 3 times a week you could use:-

    arday = new Array("day1.jpg", "day1.jpg", "day2.jpg",
    "day2.jpg", "day3.jpg", "day3.jpg", "day3.jpg");

    or whatever.


  •  

    Posting Permissions

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