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?
quick but works
var myDate = new Date();
var date = myDate.getFullYear() + '-' + ('0'+ myDate.getMonth()+1).slice(-2) + '-' + ('0'+ myDate.getDate()).slice(-2);
$("#datepicker").val(date);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With