Re[4]: Pre-selected date
2008/08/21 17:59
Viewed 5714 times
Replies: 1/4

Hello, all:

I am new to the user of this wonderful calendar widget, but I am stuck at using the "date" parameter. It does not work for me. Here is what I tried:

<html:text property="clockInSaturday" styleId="clockInSaturdayId" style="width: 20%;" />
<script type="text/javascript">
function calculateTodaysDate( dayName ) {
Date date = new Date( );
date.setDate( 21 ); // This is Thursday for example
date.setMonth( 7 );
date.setFullYear( 2008 );
var time = date.getTime( );
var oneDay = ((1000 * 60) * 60) * 24;

if( dayName == "Saturday" ) {
time -= (oneDay * 6); // Subtract 6 days, would that be Sat in the week ending on Fri, or Sat after Fri (next week)?
date.setTime( time );
return date;
}

if( dayName == "Sunday" ) {
time -= (oneDay * 5); // Subtract 5 days
date.setTime( time );
return date;
}

// Similarly I have 5 more checks for the other 5 days of the week

return date;
}

Calendar.setup(
{
inputField : "clockInSaturdayId",
ifFormat : "%H:%M",
showsTime : true,
timeFormat : "24",
firstDay : 6, // Display Saturday as the first day
date : calculateTodaysDate( "Saturday" ),
weekNumbers : false
} );
</script>

Actually, my problem is 3-fold. I want the user to enter just the hour-minute (no date), that's why I chose iFormat as "%H:%M". But the problem is that when the calendar opens, the default date is today's date and the user cannot change it if he wants to - he can only select hour-minute and enter it - that's problem # 1. The calendar with default today's date will look confusing and misleading to the user if he wants to enter time for some other date. So I tried to use the "date" parameter, but the calendar does not appear no matter how much I click in the field - that is problem # 2. What's wrong with my code?

Problem # 3: In the calculateTodaysDate function above I hard-coded a date as 08/21/2008 (Thursday) just for example. Actually, my JSP page, where I set up the above calendar, gets a weekend date (Java Date object) as a form parameter. How does the above function get DAY, MONTH, and YEAR out of that Java Date object, so it can create its own JavaScript Date object for further processing? How else would I let the user select just the time (for the right date) and display the entry as time too?

Please help. Thanks a lot in advance.

Google