Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap datepicker default date

I'm using Bootstrap datepicker and I'd like to make that when datepicker shows, default date would be set after 14 days from today. I've got this code but it doesn't work, default date is still set to today. Could anyone explain what am I missing? Thanks in advance.

JS:

  var plus14days = new Date();

  plus14days.setDate(plus14days.getDate() + 14 );
  $(".datepicker").datepicker("setValue", plus14days);
like image 985
Jess Avatar asked Aug 20 '13 07:08

Jess


People also ask

How do I change the default date format in bootstrap datepicker?

Go to line 1399 and find format: 'mm/dd/yyyy' . Now you can change the date format here.

How do I change the default date in datepicker?

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

What is the default value of datepicker?

By default, the DatePicker value is null and the Calendar popup is hidden.


1 Answers

The code you've used is right.

The date will be displayed in textbox, but not in datepicker calendar like this

enter image description here

To enable this feature you need to update it using the following code:

$(".datepicker").datepicker('update');

Now it looks like

enter image description here

Check this in JSFiddle

like image 54
Praveen Avatar answered Sep 21 '22 11:09

Praveen