Dr.Neo
Dr.Neo

Reputation: 1280

Jquery DatePicker Set default date for the Calendar

I Have multi date fields and i use DatePicker to show the calendar and choose date.
Currntly when use click the text input it shows the calendar and the default data of today
im using the script like this

$(function(){
$('input[rel="datepicker"]').datepicker({
"autoclose": true
});                                     
});

i need to set the Default date of the shown calendar to somethign like 01/01/1940
i tried

$(function(){
$('input[rel="datepicker"]').datepicker({
"autoclose": true
}); 
$('input[rel="datepicker"]').datepicker("setDate", Date(1940,01,01));                                    
});

but his one changed the input itself to 01/01/1940 instead of being empty
i need the inputs remain empty but when the user click on the input and the calnder shows it must shows Junray 1940 instead of today date

Upvotes: 0

Views: 3335

Answers (2)

SSA
SSA

Reputation: 5493

Use defaultDate property of jquery ui datepicker. Example

Also use new Date(1940,01,01) instead of Date(1940,01,01). also for setting the date.

Edit init date picker with defaultDate:

$(function(){
$("#datepicker").datepicker({
"autoclose": true,
defaultDate: new Date(1940,01,01) 
}); 

});

or if you want to set the defaultDate after datepicker is initialized then you need to use options as

$('input[rel="datepicker"]').datepicker( "option", "defaultDate",new Date(1940,01,01) );

Upvotes: 1

Haisum Usman
Haisum Usman

Reputation: 516

@Dr.Neo first you need to follow the same date format you are using.

As if you are using '/' or ',' you need to maintain the same format and to change the default date of the date picker you need to do something like this,

$("domobject").datepicker("setDate", "01/01/2014"); [Its supposed that you have defined the dateformat and other mandatory fields for amendment.]

Hope this will work for you. Wish you very best.

Upvotes: 2

Related Questions