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 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    New Jersey
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    variable destinations of a single link

    Hey all, thanks for the help the other day, but now I have a new question. I would like to set up a single clickable link that sends the visitor to one of 12 pages based off of what month it is. My question is whether or not it would be easier to use a document.write to set it up or if there is a simpler way to do it. I know I can make it work using the document.write and an array to create what is written to the page, but if there is an easier or more compact way to do it, I am all ears.

    GK

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This links you to 1.htm for january, 2.htm for feb,...

    <script language="JavaScript">
    <!--
    function chkmon() {
    m = (new Date()).getMonth() + '.html';
    location.replace(m);
    }
    //-->
    </script>

    <a href="javascript: chkmon();">Go</a>

    Here yoiu specify the page name itself.

    <script language="JavaScript">
    <!--
    months = new Array();
    months[1] = "January.htm";
    months[2] = "February.htm";
    months[3] = "March.htm";
    months[4] = "April.htm";
    ...

    function chkmon() {
    m = (new Date()).getMonth();
    location.replace(months[m]);
    }
    //-->
    </script>

    <a href="javascript: chkmon();">Go</a>

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    New York, USA
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you were to name your pages like so:
    page0.htm (january) page1.htm (february)...up to page11.htm (december)
    then this small bit of code would do what you're asking.
    <script language="javascript" type="text/javascript">
    <!--
    var today = new Date();
    document.write("<a href='page"+today.getMonth()+".htm'>click</a>")
    //-->
    </script>

    hope that helps

  • #4
    New Coder
    Join Date
    Jul 2002
    Location
    New Jersey
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    both replies helped, thanks bunches

    gk


  •  

    Posting Permissions

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