Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 19th, 2005, 5:18 AM   #1
rouli
Newbie
 
Join Date: Oct 2005
Posts: 1
Rep Power: 0 rouli is on a distinguished road
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");
to

var WeekDay = new Array("Mo","Tu","We","Th","Fr","Sa","Su");
and it worked fine (didnt do

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
rouli is offline   Reply With Quote
Old Oct 19th, 2005, 6:09 AM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
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...
__________________

tempest is offline   Reply With Quote
Old Oct 19th, 2005, 6:52 AM   #3
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
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 ]+"&nbsp;&nbsp;"+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'>&nbsp;<\/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'>&nbsp;<\/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
stevengs is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:11 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC