Click to See Complete Forum and Search --> : help requested


bob1975
05-17-2003, 10:40 PM
I found a simple script (at idpoint.com) that displays a different url each day of the week.

I need a similar script that will display a different url on each day of the year.

Here's the script:

<script language="JavaScript">
function GetTodaysURL()
{
var locationlist = new URLList
(
"1.html", // Monday
"2.html", // Tuesday
"3.html",
"4.html",
"5.html",
"6.html",
"7.html" // Sunday
);

now = new Date();
num = now.getDay();
if (num == 0) num = 7;

location.href = locationlist.list[num-1];
}

function URLList ()
{
var argv = URLList.arguments;
var argc = argv.length;
this.list = new Object();
for (var i = 0; i < argc; i++)
this.list[i] = argv[i];
this.count = argc;
return this;
}
</script>
</head>
<body>
<a href="javascript:GetTodaysURL()">javascript:GetTodaysURL()</a>
</body>
</html>

Greelmo
05-17-2003, 11:02 PM
what about making the URLList variable an array?

Greelmo
05-17-2003, 11:04 PM
sorry i didn't understand the question the first time through... couldn't you make those 7 days just 366 (leap year) things and change the code accordingly?

bob1975
05-17-2003, 11:10 PM
Can you give me an example? I'm not sure I understand. What could I use in place of the getDate method?

AdamBrill
05-18-2003, 09:40 AM
It would look something like this:<html>
<head>
<script language="JavaScript">
months = new Array();
//January...
months[0]= new Array("",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"");
//Febuary...
months[1]= new Array("",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"");
//March...
months[2]= new Array("",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"");
//April...
months[3]= new Array("",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"");
//May...
months[4]= new Array("",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"");
function GetTodaysURL(){
dateNow = new Date();
document.location.href = months[dateNow.getMonth()][dateNow.getDate()-1];
}
</script>
</head>
<body>
<a href="default.htm" onclick="GetTodaysURL(); return false;">javascript:GetTodaysURL()</a>
</body>
</html> I only put in months Jan-May, so you'll have to add in the rest...

David Harrison
05-18-2003, 10:01 AM
I thinks I've got two solutions for you, here's the first:

bob1975=new Date();
d=bob1975.getDate();
m=bob1975.getMonth()+1;
y=bob1975.getYear();
while(y>99){y-=100;}}

img=d;

for(n=m-1;n>0;n--){
if(n==1 || n==3 || n==5 || n==7 || n==8 || n==10 || n==12){img+=31;}
else if(n==4 || n==6 || n==9 || n==11){img+=30;}
else if(n==2 && (y/4)==(Math.round(y/4))){img+=29;}
else{img+=28;}}}

document.write("<img src='"+img+".gif'>");

this will load from 1.gif to 365.gif (or 366.gif on a leap year) although I haven't checked it so I may have made a mistake.


Or of course you could just use:

bob1975=new Date();
d=bob1975.getDate();
m=bob1975.getMonth()+1;
y=bob1975.getYear();
while(y>99){y-=100;}}
if(d<10){d="0"+d;}
if(m<10){m="0"+m;}
if(y<10){y="0"+y;}

document.write("<img src='"+d+""+m+""+y+".gif'>");