change image depending on date

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tjerk

    change image depending on date

    Hello all,

    I have the script below to change an image depending on the date upto
    january it worked fine but then it just stopped working does anybody have an
    idea how I can make it work again or why it doesn't work?

    Thanks in advance

    Tjerk


    <SCRIPT LANGUAGE="JavaS cript1.1">
    <!-- Beginning of JavaScript -
    today=new Date(); //determines the current date
    start=new Date("October 8, 2003"); //date you want your image to start
    displaying
    end=new Date("November 7, 2003"); //date you want your image to stop
    displaying
    start1=new Date("November 7, 2003"); //date you want your image to start
    displaying
    end1=new Date("December 6, 2003"); //date you want your image to stop
    displaying
    start2=new Date("December 6, 2003"); //date you want your image to start
    displaying
    end2=new Date("December 20, 2003"); //date you want your image to stop
    displaying
    start3=new Date("December 20, 2003"); //date you want your image to start
    displaying
    end3=new Date("January 18, 2004"); //date you want your image to stop
    displaying
    start4=new Date("January 18, 2004"); //date you want your image to start
    displaying
    end4=new Date("Febuary 4, 2003"); //date you want your image to stop
    displaying
    start5=new Date("Febuary 4, 2003"); //date you want your image to start
    displaying
    end5=new Date("Febuary 14, 2004"); //date you want your image to stop
    displaying
    start6=new Date("Febuary 25, 2004"); //date you want your image to start
    displaying
    end6=new Date("March 18, 2004"); //date you want your image to stop
    displaying
    start7=new Date("March 18, 2004"); //date you want your image to start
    displaying
    end7=new Date("April 11, 2004"); //date you want your image to stop
    displaying
    start8=new Date("April 11, 2004"); //date you want your image to start
    displaying
    end8=new Date("April 22, 2004"); //date you want your image to stop
    displaying
    start9=new Date("April 22, 2004"); //date you want your image to start
    displaying
    end9=new Date("May 5, 2004"); //date you want your image to stop displaying
    start10=new Date("May 5, 2004"); //date you want your image to start
    displaying
    end10=new Date("June 4, 2004"); //date you want your image to stop
    displaying
    start11=new Date("June 4, 2004"); //date you want your image to start
    displaying
    end11=new Date("June 11, 2004"); //date you want your image to stop
    displaying

    /*if the current date is between the start and end dates that you set,
    then your special image is displayed. Otherwise your default image is
    displayed. Be sure to include width and height tags for NN2*/

    if ((today.getTime ()>=start.getTi me()) &&
    (today.getTime( )<=end.getTime( ))){
    document.write( "<IMG SRC='Images/waar/india.gif' WIDTH='137'
    HEIGHT='103'>") ;
    }
    if ((today.getTime ()>=start1.getT ime()) &&
    (today.getTime( )<=end1.getTime ())){
    document.write( "<IMG SRC='Images/waar/thailand.gif' WIDTH='137'
    HEIGHT='103'>") ;
    }
    if ((today.getTime ()>=start2.getT ime()) &&
    (today.getTime( )<=end2.getTime ())){
    document.write( "<IMG SRC='Images/waar/laos.gif' WIDTH='137' HEIGHT='103'>") ;
    }
    if ((today.getTime ()>=start3.getT ime()) &&
    (today.getTime( )<=end3.getTime ())){
    document.write( "<IMG SRC='Images/waar/vietnam.gif' WIDTH='137'
    HEIGHT='103'>") ;
    }
    if ((today.getTime ()>=start4.getT ime()) &&
    (today.getTime( )<=end4.getTime ())){
    document.write( "<IMG SRC='Images/waar/cambodja.gif' WIDTH='137'
    HEIGHT='103'>") ;
    }
    if ((today.getTime ()>=start5.getT ime()) &&
    (today.getTime( )<=end5.getTime ())){
    document.write( "<IMG SRC='Images/waar/thailand.gif' WIDTH='137'
    HEIGHT='103'>") ;
    }
    if ((today.getTime ()>=start6.getT ime()) &&
    (today.getTime( )<=end6.getTime ())){
    document.write( "<IMG SRC='Images/waar/mexico.gif' WIDTH='137'
    HEIGHT='103'>") ;
    }
    if ((today.getTime ()>=start7.getT ime()) &&
    (today.getTime( )<=end7.getTime ())){
    document.write( "<IMG SRC='Images/waar/guatemala.gif' WIDTH='137'
    HEIGHT='103'>") ;
    }
    if ((today.getTime ()>=start8.getT ime()) &&
    (today.getTime( )<=end8.getTime ())){
    document.write( "<IMG SRC='Images/waar/honduras.gif' WIDTH='137'
    HEIGHT='103'>") ;
    }
    if ((today.getTime ()>=start9.getT ime()) &&
    (today.getTime( )<=end9.getTime ())){
    document.write( "<IMG SRC='Images/waar/nicaragua.gif' WIDTH='137'
    HEIGHT='103'>") ;
    }
    if ((today.getTime ()>=start10.get Time()) &&
    (today.getTime( )<=end10.getTim e())){
    document.write( "<IMG SRC='Images/waar/costarica.gif' WIDTH='137'
    HEIGHT='103'>") ;
    }
    if ((today.getTime ()>=start11.get Time()) &&
    (today.getTime( )<=end11.getTim e())){
    document.write( "<IMG SRC='Images/waar/usa.gif' WIDTH='137' HEIGHT='103'>") ;
    }
    else{
    document.write( "<IMG SRC='Images/waar/nederland.gif' WIDTH='137'
    HEIGHT='103'>") ;
    }
    // - End of JavaScript - -->
    </SCRIPT>


  • Evertjan.

    #2
    Re: change image depending on date

    Tjerk wrote on 17 feb 2004 in comp.lang.javas cript:
    [color=blue]
    > I have the script below to change an image depending on the date upto
    > january it worked fine but then it just stopped working does anybody
    > have an idea how I can make it work again or why it doesn't work?
    >[/color]

    Dag Tjerk

    Het is niet "Febuary" maar "February"
    Je zult in end4 en start5 2004 bedoelen waar 2003 staat.

    de >= en de > schelen 1 miliseconde
    javascript versie specificeren is niet zinvol
    "<!-- Beginning of JavaScript -" ook niet erg zinvol

    =============== =============== =============== ===

    Ik heb de zaak nog eens wat leesbaarder opgesteld,
    probeer het maar eens zo:

    <SCRIPT>
    var start = new Array()
    var end = new Array()
    var beeld = new Array()

    var today=new Date()

    start[0]=new Date("October 8, 2003")
    end[0]=new Date("November 7, 2003")
    start[1]=new Date("November 7, 2003")
    end[1]=new Date("December 6, 2003")
    start[2]=new Date("December 6, 2003")
    end[2]=new Date("December 20, 2003")
    start[3]=new Date("December 20, 2003")
    end[3]=new Date("January 18, 2004")
    start[4]=new Date("January 18, 2004")
    end[4]=new Date("February 4, 2004")
    start[5]=new Date("February 4, 2004")
    end[5]=new Date("February 20, 2004")
    // end[5] date changed for testing
    start[6]=new Date("February 25, 2004")
    end[6]=new Date("March 18, 2004")
    start[7]=new Date("March 18, 2004")
    end[7]=new Date("April 11, 2004")
    start[8]=new Date("April 11, 2004")
    end[8]=new Date("April 22, 2004")
    start[9]=new Date("April 22, 2004")
    end[9]=new Date("May 5, 2004")
    start[10]=new Date("May 5, 2004")
    end[10]=new Date("June 4, 2004")
    start[11]=new Date("June 4, 2004")
    end[11]=new Date("June 11, 2004")
    beeld[0]='india.gif'
    beeld[1]='thailand.gif'
    beeld[2]='laos.gif'
    beeld[3]='vietnam.gif'
    beeld[4]='cambodja.gif'
    beeld[5]='thailand.gif'
    beeld[6]='mexico.gif'
    beeld[7]='guatemala.gif '
    beeld[8]='honduras.gif'
    beeld[9]='nicaragua.gif '
    beeld[10]='costarica.gif '
    beeld[11]='usa.gif'


    var b = 'nederland.gif'
    for (i=0;i<=11;i++) {
    if ((today.getTime () > start[i].getTime()) &&
    (today.getTime( ) < end[i].getTime()) ){
    b = beeld[i]
    i=100
    }
    }

    var t="<IMG SRC='Images/waar/" + b + "' WIDTH='137' HEIGHT='103'>"
    document.write( t)

    </SCRIPT>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Dr John Stockton

      #3
      Re: change image depending on date

      JRS: In article <c0sv1k$3i0$1@r eader10.wxs.nl> , seen in
      news:comp.lang. javascript, Tjerk <info@tjerkstra vels.com> posted at Tue,
      17 Feb 2004 12:47:29 :-[color=blue]
      >
      >I have the script below to change an image depending on the date upto
      >january it worked fine but then it just stopped working does anybody have an
      >idea how I can make it work again or why it doesn't work?[/color]
      [color=blue]
      > ...[/color]
      [color=blue]
      >start4=new Date("January 18, 2004");
      > ...
      >end4=new Date("Febuary 14, 2004");[/color]

      It will work if we ever have a month called Febuary. The present month
      is called February.

      Better to use new Date("2003/02/14") // less typing.


      Your code is very repetitive. It could be shortened by using array
      data, something like :-

      var Data = [
      {C:"potaniland" , S:"2004/05/06", F:"2004/06/07"},
      {C:"lumbago", S: ...
      ... ]

      for (J=0; J<Data.length;J ++) with (Data[J])
      if (today>=S && today<F)
      document.write( "<IMG ... waar/", C, ".gif ...")

      where today is now a string YYYY/MM/DD.

      In fact, you only need to store the start date; scan until you find one
      <= today, then finish (use break). Put a "catch all" of 9999/99/99 at
      the end, preceded by one for Nederland.

      Compare <URL:http://www.merlyn.demo n.co.uk/js-date1.htm#SS>

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
      <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

      Comment

      Working...