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 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2003
    Location
    sunny england
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how do I change an image depending on which month it is?

    using the get.date function in javascript, how can I retrieve the month, and then use this information to display a month-dependant image (ie if the month is october, then the image will be unique to october and only be shown in october)
    I suppose it is a bit like a calendar that knows which displays the current month as that is of most use, but I'm using images instead, does anyone know how I may achieve this?

    every help appreciated,
    thanks!

  • #2
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    396
    Thanks
    2
    Thanked 30 Times in 30 Posts
    Just create a series of images named month0.jpg through month11.jpg thn:


    <html>
    <head>
    <title> monthly image</title>
    <script language="JavaScript">
    <!--
    function setimage()
    {
    var thedate=new Date();
    var nmonth=thetime.getMonth();
    var str='month'+nmonth+'.jpg';
    document.images['monthimage'].src=str;
    }
    </script>
    </head>
    <body onLoad="setimage()">
    <img name="monthimage" src="">
    The rest of the page
    </body>
    </html>
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&

  • #3
    New Coder
    Join Date
    Sep 2003
    Location
    sunny england
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi COBOLdinosaur!

    that code looked perfect, so i made the page, made the images, and the only part of the code I changed was .jpg to .gif, the page is coming back with an error though, and I cant figure out what is wrong!

    here's the page i made,

    thankyou for your time

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Looks like you got a little pseudo-variable in your head (:P):

    Code:
    var thedate = new Date();
    var nmonth = thetime.getMonth();
    ...ought to be:

    Code:
    var thedate=new Date();
    var nmonth=thedate.getMonth();
    Hope that helps!

    Happy coding!

  • #5
    New Coder
    Join Date
    Sep 2003
    Location
    sunny england
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thankyou both so much, hehe well I'm a bit stupid for missing that bit of code

    thanks

  • #6
    New to the CF scene
    Join Date
    Sep 2003
    Location
    The ardennen, Belgium
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dear all,

    I also would like to use this code, but I have some problems if I want to
    use the function for multiple images, also can I not pass the image to an popup function

    <html>
    <head>
    <title> day of weekimage</title>

    <script language="JavaScript1.2">
    function setimage()
    {
    var thedate=new Date();
    var ndayofweek=thedate.getUTCDay();
    var strthumb='thumbnails/verbouwing_'+ndayofweek+'_';
    var strimage='images/verbouwing_'+ndayofweek+'_';

    //fill in here every new picture
    document.images['thumb20031013'].src=strthumb+'20031013'+'.jpg';
    document.images['image20031013'].src=strimage+'20031013'+'.jpg';

    document.images['thumb20031014'].src=strthumb+'20031014'+'.jpg';
    document.images['image20031014'].src=strimage+'20031014'+'.jpg';
    }
    </script>
    </head>

    <body onLoad="setimage()">
    <img class='photo' align='left' name='thumb20031013' src='' id='verbouwing_20031013' alt='klik om te vergroten...' onclick="imgPop(image20031013);" onload="fnNormalize(this);" onMouseOver="fnBlur(this);" onMouseOut="fnNormalize(this);">

    <img class='photo' align='left' name='thumb20031014' src='' id='verbouwing_20031014' alt='klik om te vergroten...' onclick="imgPop(image20031014);" onload="fnNormalize(this);" onMouseOver="fnBlur(this);" onMouseOut="fnNormalize(this);">
    </body>
    </html>


    greetings
    Berton Christophe
    it is not the strongest nor the most intelligent that will survive but the one most responsive to change

  • #7
    New to the CF scene
    Join Date
    Sep 2003
    Location
    The ardennen, Belgium
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    found it

    I wanted to go to fast,

    function setpopimage(myimage)
    {
    var thedate=new Date();
    var ndayofweek=thedate.getUTCDay();
    var strimage='images/verbouwing_'+ndayofweek+'_'+myimage+'.jpg';

    imgPop(strimage);
    }



    <img class='photo' align='left' name='thumb20031014' src='' id='verbouwing_20031014' alt='klik om te vergroten...' onclick="setpopimage('20031014');" onload="fnNormalize(this);" onMouseOver="fnBlur(this);" onMouseOut="fnNormalize(this);">
    Berton Christophe
    it is not the strongest nor the most intelligent that will survive but the one most responsive to change


  •  

    Posting Permissions

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