I have a very simple jQuery Datepicker calendar:
$(document).ready(function(){
$("#date_pretty").datepicker({
});
});
and of course in the HTML...
<input type="text" size="10" value="" id="date_pretty"/>
Today's date is nicely highlighted for the user when they bring up the calendar, but how do I get jQuery to pre-populate the textbox itself with today's date on page load, without the user doing anything? 99% of the time, the today's date default will be what they want.
Set to today:
Set to yesterday:
And so on with any number of days before or after today's date.
See jQuery UI › Methods › setDate.
The solution is:
Thanks grayghost!
In order to set the datepicker to a certain default time (the current date in my case) on loading, AND then have the option to choose another date the syntax is :
Update: There are reports this no longer works in Chrome.
This is concise and does the job:
Just thought I'd add my two cents. The picker is being used on an add/update form, so it needed to show the date coming from the database if editing an existing record, or show today's date if not. Below is working fine for me:
To pre-populate date, first you have to initialise datepicker, then pass setDate parameter value.