JQuery datepicker set defaultvalue

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

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

This is the first January 1970 by default when a datapicker pops up. How to change the default value?

+3
source share
3 answers

You can do this from an event show, but I have to say that the datepicker documentation is really missing. 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 is mine 01.05.2012, put the actual date.

+7
source

fast but working

  var myDate = new Date();
  var date = myDate.getFullYear() + '-' + ('0'+ myDate.getMonth()+1).slice(-2) + '-' + ('0'+ myDate.getDate()).slice(-2);
  $("#datepicker").val(date);
+6
source

bootstrap-datepicker.js(~ 331) :

date = new Date(1971, 1, 1, 0, 0, 0),

date = new Date(),
-3

All Articles