Skip to content Skip to sidebar Skip to footer

Setting Default Date For Jqueryui Datepicker

I have a simple form for generating reports that I am adding a jqueryUI datepicker to. The problem I am having is when I try to repopulate the fields with the info from the user. J

Solution 1:

Set the date to highlight on first opening if the field is blank. Specify either an actual date via a Date object or as a string in the current dateFormat, or a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null for today.

Initialize a datepicker with the defaultDate option specified.

$( ".selector" ).datepicker({ defaultDate: +7 });

Get or set the defaultDate option, after init.

//gettervar defaultDate = $( ".selector" ).datepicker( "option", "defaultDate" );

//setter
$( ".selector" ).datepicker( "option", "defaultDate", +7 );

http://jqueryui.com/demos/datepicker/#option-defaultDate

Fiddle: http://jsfiddle.net/iambriansreed/gMNrZ/

Solution 2:

You can do this while populating your date:

$( "#startdate" ).datepicker( "setDate" , date );

see this

Solution 3:

http://docs.jquery.com/UI/Datepicker#option-minDate

var dateOptions = { 
  dateFormat: "mm/dd/yy", 
  constrainInput: true, 
  gotoCurrent: true, 
  minDate: newDate()
  };

  $('.date').datepicker(dateOptions);

Post a Comment for "Setting Default Date For Jqueryui Datepicker"