views:

5668

answers:

4

I have declared a date picker instance as follows:

    $("#datePickerId").datepicker(
    { dateFormat: 'DD, d MM yy',
      minDate: 0,
      showOn: 'button',
      buttonImage: '../../images/calendar.gif',
      buttonImageOnly: true,
      hideIfNoPrevNext: true
    }
   );

I now want to change to the minDate option so I do this:

$('#datePickerId').datepicker('option', 'minDate', 3);

But nothing happens. Was I suppose to do anything else? What other possible causes could there be?

+3  A: 

Draco,

You can do it like this:

$("#datePickerId").datepicker(
    { dateFormat: 'DD, d MM yy',
      minDate: new Date(2009, 10 - 1, 25), // it will set minDate from 25 October 2009
      showOn: 'button',
      buttonImage: '../../images/calendar.gif',
      buttonImageOnly: true,
      hideIfNoPrevNext: true
    }
   );

remember to write -1 after month (ex. for june is -> 6 -1)

Indent your code 4 spaces to correctly format and syntax highlight it.
thenduks
+2  A: 

Use minDate as string:

$('#datePickerId').datepicker({minDate: '0'});

This would set today as minimum selectable date .

bogart
A: 

Why should I write -1 after month?

dago
Months in JavaScript dates are zero based. So 0 = January, 1 = February, etc...
aherrick
A: 

Month start from 0. 0 = January, 1 = February, 2 = March, ..., 11 = December.

koala