Results 1 to 2 of 2

Thread: Help with Image Swap by Day

  1. #1
    Join Date
    Dec 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help with Image Swap by Day

    okay. I have been searching from forums to sites and I have yet found a script that allows image swapping by actual day. Here is what I want to do:

    On page load to see the day (ie Wednesday, Friday, Saturday) then load that day's image.

    here's what I came up with - my C is very rusty and I know it sorta goes like this:


    <SCRIPT language="JavaScript">
    var wednesdayImage = 'Wednesday.gif';
    var fridayImage = 'friday.gif';
    var saturdayImage = 'saturday.gif';
    var now = new Date();
    var tday= new Array('Sunday','Sun','Monday','Mon', 'Tuesday','Tue', 'Wednesday','Wed','Thursday','Thr','Friday','Fri','Saturday','Sat');
    if (tday >= Wednesday && tday <= Saturday)
    document.write('<IMG SRC="' + wednesdayImage + '">');
    else
    document.write('<IMG SRC="' + fridayImage + '">');
    else
    document.write('<IMG SRC="' + saturdayImage + '">');
    </SCRIPT>


    Am I wrong? help please.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You're overcomplicating things. And what does C have to do with Javascript? They're fairly far removed
    Code:
    <script type="text/javascript">
    
    // imgs is an array of images, from 0 (Sunday) to 6 (Saturday).
    var imgs = new Array(),
      today = new Date();
    today = today.getDay();
    imgs[3] = "Wednesday.gif";
    imgs[5] = "friday.gif";
    imgs[6] = "saturday.gif";
    document.write("<img src=\"" + imgs[today] + "\"/>");
    </script>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •