automatically set jQuery UI datepicker on load
When a form load I want it to already have the current date plus 5 days. So its 2/22/2011, When the page loads the text box the datepicker belongs to should show 3/1/2011. I know how to set default date to 5 days from the current date but I need it to be in the text box when开发者_如何学JAVA the page loads.
There is actually a much easier way.
$("#datepicker").datepicker();
$("#datepicker").datepicker("setDate", "+5d");
Just figured it out.
I must be missing something, you would do something like:
$(function() {
//set your date picker
$('#test').datepicker();
//get the current date
var yourDate = new Date();
//set the current date to today + 5 days
yourDate.setDate(yourDate.getDate() + 5)
//format the date in the right format
formatDate = (yourDate.getMonth() + 1) + '/' + yourDate.getDate() + '/' + yourDate.getFullYear();
//set the input value
$('#test').val(formatDate);
});
Working sample here here...
精彩评论