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

    display different image each day of the month

    I have a random image generator on my web site at


    The random image is loaded from potshots.html by clicking on TODAY'S POTSHOT at the bottom of the home page.

    This javascript is working satisfactorily, but having written it, I find its not quite what I want. What I really want is a different potshot to come up each day of the month. I have 31 potshots, so this should be no problem. What I would like to do is to test what day in the month it is, and then select that array element. For instance, today is wednesday Nov 9, so clicking TODAYS POTSHOT should bring up element [9]. Tomorrow, the same click sequence will bring up element [10] and so forth.

    How do I find the numeric value of the day of the month? And then having found it use that as the array index value?

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Thanked 27 Times in 25 Posts

    If you're using js, then be sure to implement a default img and use js to switch the src of that img to the correct one for that day of the month.

    (rough) e.g.
    var srcImg = document.getElementById('dailyImg');
    var d = new Date();
    var monthDay = d.getDate();
    srcImg.src = monthDay + '.jpg';
    A more robust approach might be to use PHP which would do the job even when the user doesn't have js enabled.

    Last edited by Bill Posters; 11-09-2006 at 11:15 AM.


    Posting Permissions

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