Click to See Complete Forum and Search --> : Link changing every month, but not the text?
Labello
07-27-2003, 05:05 PM
I´ve looked around but haven´t found a javascript doing what I want.
I have a link where I want to keep the text, but change the direction it points to every month. Preferably a javascript in the <head> and a "trigger" in the <body>.
Anyone who knows a good one?
Thanks!
David Harrison
07-27-2003, 05:37 PM
This sounds exactly what you're looking for:
Labello
07-27-2003, 06:02 PM
Yes lavalamp, it seems right.
Beeing a javascript amateur however, I wonder what to do with the the <body> part?
<body>
<script type="text/javascript"><!--
create_month_link();
//--></script>
</body>
The link I have at the moment looks like this:
<a href="#" onMouseOver="window.status='02.';return true" onMouseOut=";window.status='';return true" onClick="window.focus( )" target="main_frame" class="startlink">Here´s the text I want to keep even if I´m changing the direction every month »</a>
Is it possible to do a href="javascript:create_month_link();" or something like that?
Really appreciating the help!
David Harrison
07-27-2003, 06:20 PM
It's best not to put javascript in the href. So what you could do is this:
<a href="#" onclick="this.href=link_array[month];return true;" onmouseover="window.status='02.';return true" onmouseout="window.status='';return true;" target="main_frame" class="startlink">Here´s the text I want to keep even if I´m changing the direction every month »</a>
By the way, is the window.status message anything to do with the current month?
If so do this:
<a href="#" onclick="this.href=link_array[month];return true;" onmouseover="window.status=month+'.';return true" onmouseout="window.status='';return true;" target="main_frame" class="startlink">Here´s the text I want to keep even if I´m changing the direction every month »</a>
And just inside the closing script tag put this:
month=(month<10)?"0"+month:month;
Or more simply rather that put all of the HTML there in the body you could tidy it all up, like in my first example, by replacing:
document.write('<a href="'+link_array[month]+'">Go to this months page</a>');
with:
document.write('<a href="#" onclick="this.href='+link_array[month]+';return true;" onmouseover="window.status=\'02.\';return true;" onmouseout="window.status=\'\';return true;" target="main_frame" class="startlink">Here´s the text I want to keep even if I´m changing the direction every month »</a>');
Sorry if this all seems really complicated, but I don't have time to explain it fully, I should already be offline now.
Labello
07-27-2003, 06:43 PM
Thanks for the help, it´s almost working now!
Unfortunately the links says "undefined" when I click on it. Does it matter if the link in the script is absolute or relative?
var link_array=new Array();
link_array[0]="thepageforjanuary.htm";
link_array[1]="http://www.mypage.com/thepageforjanuary.htm";
link_array[2]="http://www.mar.com/";.........
Or is it some other problem?
David Harrison
07-30-2003, 01:16 PM
it can be relative or absolute, just like a normal link. Are you sure that you've got all of the path names correct?