Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery-UI datepicker default date

I have a problem with the jQuery-UI datepicker, I have searched and searched but I didn't find the answer. I have the following code:

<script type="text/javascript"> $(function() {                    $("#birthdate" ).datepicker({         changeMonth: true,         changeYear: true,         yearRange: '1920:2010',         dateFormat : 'dd-mm-yy',         defaultDate: '01-01-1985'     }); }); </script> 

I want that when the user click in the #birthdate input that the current date selected to be 01-01-1985, now it's setting the current date.

like image 870
Alesio Avatar asked Sep 30 '10 08:09

Alesio


People also ask

How do I set a default date in datepicker?

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

How can change date format in jQuery UI datepicker?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

How do I change date format in datepicker?

You can add an Input box of type text to your web page. Inside the script, you can define the date format according to your requirement. In the script section, simply attach the input type text element to the datepicker() method.

How can I select current date in datepicker?

To set current date in control to which jQuery UI datepicker bind, use setDate() method. Pass date object which needs to be set as an argument to setDate() method. If you want to set it to current date then you can pass 'today' as argument.


1 Answers

Try passing in a Date object instead. I can't see why it doesn't work in the format you have entered:

<script type="text/javascript"> $(function() {                    $("#birthdate" ).datepicker({         changeMonth: true,         changeYear: true,         yearRange: '1920:2010',         dateFormat : 'dd-mm-yy',         defaultDate: new Date(1985, 00, 01)     }); }); </script> 

http://api.jqueryui.com/datepicker/#option-defaultDate

Specify either an actual date via a Date object or as a string in the current dateFormat, or a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null for today.

like image 84
Codesleuth Avatar answered Sep 21 '22 23:09

Codesleuth