PDA

View Full Version : Whats wrong?


hskwebmaster
10-10-2002, 11:37 PM
I´ve got this script on my page.
The page is based on 2 frames(meny and main).
The meny is build by using <span>, it creates a threestructure.
One option is "Calender"
The ide is that the script should create a link to the calender for a spec. month.
To day it looks something like this:
<span id...)><a href="month.htm">text</a></span>
And I want it to look something like this:
<span id...><a href="javascript">text</a></span>

And by this gaining that I dont need to update the link every month.

This is what I´ve come up whit so far:
<script language="JavaScript">

function manad()
{
var tiden=new Date();

var manad=tiden.getMonth();
var iaar=tiden.getYear();

if (manad==0)
manad="jan";
if (manad==1)
manad="feb";
if (manad==2)
manad="mars";
if (manad==3)
manad="april";
if (manad==4)
manad="maj";
if (manad==5)
manad="juni";
if (manad==6)
manad="juli";
if (manad==7)
manad="aug";
if (manad==8)
manad="sep";
if (manad==9)
manad="okt";
if (manad==10)
manad="nov";
if (manad==11)
manad="dec";
document.write('<a href=../kalender/'+iaar+'/'+manad+'.htm>'+manad+'</a>') *
}
</script>

* I´m guesing this is where it gose wrong?

Pleace help me...

boywonder
10-11-2002, 12:18 AM
Typically you wouldn't need to do all those ifs. You could use the value returned from getMonth to grab the month name from an array. This should work for you...

function manad()
{
var tiden=new Date();
var manad=tiden.getMonth();
var iaar=tiden.getYear();
var arMonth = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
document.write('<a href=../kalender/'+iaar+'/'+arMonth[manad]+'.htm>'+arMonth[manad]+'</a>')
}

hope that helps