Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datepicker set date during page load

I have a datepicker but it doesn't show date in the input when page is first time loaded. The date is set only after click.

$('#starts-on').datepicker({ 
            dateFormat: 'MM dd, yy' ,
        }).datepicker( "option", { setDate:"0",
                maxDate:'+3y -1d',
                minDate:'0' } );

How can the date be loaded during first time page loading? Moreover, i want to disable the text box to add text. Any help?

like image 718
nebula Avatar asked Apr 26 '13 09:04

nebula


2 Answers

you could use setDate, like:

$(document).ready(function() {
    $('#starts-on').datepicker("setDate", your_Date_here);
});

Added:

$(document).ready(function() {
    $('#starts-on').datepicker({ 
            dateFormat: 'MM dd, yy' ,
        }).datepicker( "option", { setDate:"0",
                maxDate:'+3y -1d',
                minDate:'0' } );
    $('#starts-on').datepicker("setDate", "0"); //"0" for current date
});
like image 149
Sudhir Bastakoti Avatar answered Nov 12 '22 09:11

Sudhir Bastakoti


You have to put the initialization object literal all in the first call of datepicker:

$( "#starts-on" ).datepicker({
    dateFormat: 'MM dd, yy' ,
    setDate:"0",
    maxDate:'+3y -1d',
    minDate:'0'
});

Setting an option for datepicker after initialization has a different syntax (see the example for dateformat here).

like image 1
Alepac Avatar answered Nov 12 '22 10:11

Alepac