![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2005
Posts: 1
Rep Power: 0
![]() |
need help with a javascript calendar
hi everyone,
i am using a javascript calendar but i want to start the week from monday instead of sunday. i changed an array var WeekDay = new Array("Su","Mo","Tu","We","Th","Fr","Sa");var WeekDay = new Array("Mo","Tu","We","Th","Fr","Sa","Su");much effort lol ), but i discovered a bug where December 2000 started on a monday instead of a sunday so i thought there might be other similar bugs too... is there any function i should use that would start the week from monday? if anyone has ideas please let me know thank u ![]() |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
Well, if you don't know much programming that was a creative trick, however, your dates are going to be wrong too and it probably wouldn't be best to do it that way. Paste the entire script and maybe someone can help you...
__________________
|
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
A couple of years back, I was forced to use Javascript for a grade in Web Programming and a calendar was one of the excercises:
[PHP]<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta name="description" content="Web Programming Excercises - WS2003"> <meta name="author" content="Steven G. Smith"> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <title>Toil N Trouble - Web Programming - Excercise 02</title> <link rel="stylesheet" type="text/css" href="../../css/format.css"> </head> <body class="calendar"> <div class="tit">Web Programming</div> <div class="subt">Dynamic Calendar</div> <script type="text/javascript"> <!-- // Create Arrays holding the pertinent information for the FOR-Loops. var MonthNames = new Array ( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ); var MonthLengths = new Array ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); var DayNames = new Array ( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ); // Create two Date Variables and use them to extract the current calendar view from the system. var CurrentDate = new Date(); // Create date object CurrentDate var TodaysMonth = CurrentDate.getMonth(); // Extract current Month (0-11) var TodaysYear = CurrentDate.getFullYear(); // Extract current Year (2003) var TodaysDay = CurrentDate.getDay(); // Extract current Day (0-6) var TodaysDate = CurrentDate.getDate(); // Extract current Date (0-31) var MonthLength = MonthLengths[ TodaysMonth ]; // Figure Length of current Month if (( TodaysMonth == 1 ) && ( TodaysYear % 4 == 0 )) // Leap Year MonthLength += 1; // - 29 days when divisible by 4 var Day = new Date(); // GP date object Day Day.setDate( MonthLength ); // Set Day date to end of month var LastDay = Day.getDay(); // Extract day value for end of month Day.setDate( 1 ); // Set Day date to first of month var FirstDay = Day.getDay(); // Extract day value for first of month // Print out the "Month and Year" Header. document.write( "<table align='center' class='calendar'>" ); document.write( "<tr><td colspan='7' class='month'>" +MonthNames[ TodaysMonth ]+" "+TodaysYear+"<\/td><\/tr>" ); // Print out the "Day ( Mo.-Fri. )" Headers. document.write( "<tr>" ); for(var i = 0; i <= 6; i++ ){ document.write( "<td class='weekday'>"+DayNames[ i ]+"<\/td>" ); } document.write( "<\/tr>" ); // Leave blanks til the first of the month and then print out the rest of the month line for line. document.write( "<tr>" ); for( var i = 0; i < FirstDay; i++ ) { document.write( "<td class='date'> <\/td>" ); } // Now Print out the Dates, line for line, while basing the color on the Day. for ( var i = 1; i <= MonthLength; i++ ) { Day.setDate( i ); var whichday = Day.getDay(); if( Day.getDate() != TodaysDate ) { switch( whichday ) { case 0: document.write( "<td class='sun'>" ); break; case 6: document.write( "<td class='sat'>" ); break; default: document.write( "<td class='date'>" ); break; } } else { document.write( "<td class='today'>" ); } document.write( +i+"<\/td>" ); if( whichday == 6 && i == MonthLength ) { document.write( "<\/tr>" ); } // Close the Row if last Saturday. else { if( whichday == 6 ) { document.write( "<\/tr><tr>" ); } } // New Row on other Saturday. } // All that is still required are 7-LastDay Blanks following the last date. for ( i=0; i<6-LastDay; i++ ) { document.write( "<td class='date'> <\/td>" ); } document.write( "<\/tr><\/table>" ); //--> </script> <div class="foot"><a href="../webprog.html">Back</a></div> </body> </html>[/PHP] It starts with Sunday, but it would be easy to change that.
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|