...

View Full Version : variable destinations of a single link



GateKeeper
07-30-2002, 11:24 PM
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

x_goose_x
07-30-2002, 11:42 PM
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>

boywonder
07-30-2002, 11:45 PM
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

GateKeeper
07-30-2002, 11:56 PM
both replies helped, thanks bunches

gk



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum