homepage Welcome to WebmasterWorld Guest from 54.166.8.138
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
daily link
a different link for each month + day
Right Reading




msg:3739564
 5:42 am on Sep 6, 2008 (gmt 0)

I'm having trouble with what seems like it should be an easy script to write (but then, I'm a designer not a programmer). What I want to do is to serve up today's date with a different link for each day of the year (366 different links depending on today's date). I only care about month and day, not the year (September 5 will always link to a certain page, no matter the year; "September 5" will always be the anchor text for that date). I'm having trouble with the "and" operator in the condition "if it's september and it's day 5." Thanks for any help.

 

Fotiman




msg:3740433
 1:34 pm on Sep 8, 2008 (gmt 0)

Perhaps something along these lines:

var today = new Date(); 
var dayOfMonth = today.getDate() - 1;
var month = today.getMonth();
var links = [
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // Jan
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29], // Feb
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // Mar
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30], // Apr
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // May
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30], // Jun
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // Jul
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // Aug
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30], // Sep
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // Oct
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30], // Nov
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31] // Dec
];
alert(links[month][dayOfMonth]);

Replace the numbers with the desired link values. All I've done is created an array that has 12 values (1 for each month). The 12 values happen to be another array containing the number of items that correspond to the number of days in the month. I then used the current month and day of the month to index into my top level array and its nested array.

Right Reading




msg:3747180
 3:15 pm on Sep 18, 2008 (gmt 0)

Thanks, Fotiman! That's interesting -- I'll give it a try.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved