How to set default date for inline datePicker for jQuery?

I use this jQuery inline datePicker sample , but I don't know how to set the selected date to default. Do you have any ideas?

+5
source share
5 answers
$('.date-pick').datePicker({
    defaultDate: $.datepicker.parseDate("d m y", "31 8 2009")
})
+8
source

You will need to use the method dpSetSelected. I added this to the code on the example page below:

$(function()
{
    $('.turn-me-into-datepicker')
        .datePicker({inline:true})
        .dpSetSelected('01/04/2010') // The string should be in Date.format
        .bind(
            'dateSelected',
            function(e, selectedDate, $td)
            {
                console.log('You selected ' + selectedDate);
            }
        );
});

As already mentioned, if you have changed Date.format , you need to make sure that the string is in the format in which you changed it.

+3
source

: http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerDefaultToday.html

$(function() {
     var date = new Date(); // replace with your date
     $('.date-pick').datePicker().val(date.asString()).trigger('change');
});

:

<input class="date-pick" type="text" value="1/1/2009" />
+2
source

You can simply set the value of this input field, for example $ ('# date-picker'). val ('22 Jun 2015 ');

+1
source
$("selector").datepicker('setDate', 'today');

To install the user interface widget and input element.

0
source

All Articles