xander27 xander27 - 1 month ago 8
jQuery Question

JQuery datepicker set defaultvalue

I use this date picker. I need input to be empty on page loading, but set default value to today on datepicke popap. Now when I jast write:

$(".dp").datepicker({
format: 'dd.mm.yyyy',
startDate: '01.01.2012',
endDate: ''
});;


It's first Janary 1970 by default when datapicker is popuping. How can I change default value?

Answer Source

You can do it from the show event, but I have to say that datepicker's documentation is really lacking. Here's how:

(function() {

  $(".dp").datepicker({
    format: 'dd.mm.yyyy',
    startDate: '01.01.2012',
    endDate: ''
  }).on("show", function() {
    $(this).val("01.05.2012").datepicker('update');
  });

})();

Naturally, where I have 01.05.2012, put the actual date.