PDA

View Full Version : Newbie easy javascript problem?


rsvore
04-08-2005, 03:06 PM
I'm trying to create the Javascript below to look into a folder called "week1" and in that folder I have 7 HTML files named Sunday, Monday and so on. When the javascritp runs I want it to find the day today on the user computer and select the appropriate HTML file for that day of the week. Any help is appreciated.

Thank you.
Rob

<SCRIPT LANGUAGE="JavaScript">
<!--
var dayArray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var today = new Date();
var day = dayArray[''.getDay()];
window.location = "Week1/" + dayArray + ".html";
//-->
</SCRIPT>

snowieken
04-08-2005, 03:23 PM
<SCRIPT LANGUAGE="JavaScript">
<!--
var dayArray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var today = new Date();
var day = dayArray[today.getDay()];
window.location = "Week1/" + day + ".html";
//-->
</SCRIPT>What you did wrong:
You didn't set the variable "day" correctly. You had to apply getDate() to "today".
And in your window.location line, you pointed to dayArray instead of day, causing the script to direct you to Week1/Sunday, Monday, ..., Saturday.html, which naturally it doesn't find.

Glad to help! :)

rsvore
04-08-2005, 06:52 PM
Snowieken,

Thank you so much for tweaking the script I have it working with your help.

Rob