olo olo - 3 months ago 4x
jQuery Question

bootstrap datepicker today as default

I am using this bootstrap-datepicker for my datepicker. I'd like the datepicker to choose "today" for start day or default day.
I cannot figure out how to set "today" automatically, so I did an inefficient way


<input type="text" value ="today();" id="datepicker"/>


function today(){
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
document.write(curr_date + "-" + curr_month + "-" + curr_year);

Online Sample: http://jsfiddle.net/BXZk2/

Just looking for an easy solution to make the default day as "TODAY".


Nic Nic

This should work:

$("#datepicker").datepicker("setDate", new Date());

And for autoclose (fiddle):

        "setDate": new Date(),
        "autoclose": true

jQuery > datepicker API