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 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Link that Changes Based on Date

    I'm trying to build a link on my site that will link to a different page based on what month it is. This is for people to access a monthly calendar. The idea is that the user can click on the "Calendar" link and have it automatically direct them to that months calendar page. Each month will be on a different page. I have almost no experience with Javascript so the following code is my compilation of various sources on the internet. Any help getting this to work would be much apprectiated.

    This is located in the "head" section of my page
    Code:
    <script type="text/javascript">
    
    var d=new Date()
    
    var month=new Array(12)
    month[0]="january.htm"
    month[1]="february.htm"
    month[2]="march.htm"
    month[3]="april.htm"
    month[4]="may.htm"
    month[5]="june.htm"
    month[6]="july.htm"
    month[7]="august.htm"
    month[8]="september.htm"
    month[9]="october.htm"
    month[10]="november.htm"
    month[11]="december.htm"
    </script>
    and here is where I'm trying to put the link
    Code:
    <ul id="nav">
    	  	  <li id="t-home"><a href="home.htm">Home</a></li>
    		  <li id="t-about"><a href="about.htm">FIT Ultimate</a></li>
    		  <li id="t-news"><a href="news.htm">News</a></li>
    	    	  <li id="t-photos"><a href="photos.htm">Photos</a></li>
    		  <li id="t-roster"><a href="roster.htm">Roster</a></li>
              <script type="text/javascript">document.write("<li id="t-calendar"><a href="calendar/"+month+"">Calendar</a></li>")</script>
          	</ul>
    Thanks!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Try this:-

    <script type="text/javascript">

    var d = new Date()
    var mm = d.getMonth();

    var month=new Array(12)
    month[0]="january.htm"
    month[1]="february.htm"
    month[2]="march.htm"
    month[3]="april.htm"
    month[4]="may.htm"
    month[5]="june.htm"
    month[6]="july.htm"
    month[7]="august.htm"
    month[8]="september.htm"
    month[9]="october.htm"
    month[10]="november.htm"
    month[11]="december.htm"

    </script>

    <ul id="nav">
    <li id="t-home"><a href="home.htm">Home</a></li>
    <li id="t-about"><a href="about.htm">FIT Ultimate</a></li>
    <li id="t-news"><a href="news.htm">News</a></li>
    <li id="t-photos"><a href="photos.htm">Photos</a></li>
    <li id="t-roster"><a href="roster.htm">Roster</a></li>

    <script type = "text/javascript">
    document.write("<br><br><a href=month[mm]>Calendar</a>")
    </script>

    It is your responsibility to die() if necessary….. - PHP Manual

  • #3
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by Philip M View Post
    Code:
    document.write("<br><br><a href=month[mm]>Calendar</a>")
    haste makes waste thats gotta be

    Code:
    document.write("<br><br><a href='" + month[mm] + "'>Calendar</a>")
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

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