datepicker - populating inputs for month/day/year
What I'm looking to do is something similar to this, except with inputs instead of selects:
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerIntoSelects.html
I'm hoping this is relatively easy but I didn't see a similar example in the datepicker demo's....help??
Based on the above example, I've gotten the below to work.... Any suggestions on how to do this w/ jqueryui datepicker?
- $('#date-pick')
.datePicker(
{
createButton:false,
startDate:'01/01/2005',
endDate:'31/12/2010'
}
).bind(
'click',
function()
{
updateInputs($(this).dpGetSelected()[0]);
$(this).dpDisplay();
return false;
}
).bind(
// when a date is selected update the SELECTs
'dateSelected',
function(e, selectedDate, $td, state)
{
updateInputs(selectedDate);
}
).bind(
'dpClosed',
function(e, selected)
{
updateInputs(selected[0]);
}
);
var updateInputs = function (selectedDate)
{
var selectedDate = new Date(selectedDate);
$('#d').val(selectedDate.getDate());
$('#m').val(selectedDate.getMonth()+1);
$('#y').val(selectedDate.getFullYear());
}
// listen for when the selects are changed and update the picker
$('#d, #m, #y')
.bind(
'blur',
function()
{
var d = new Date(
$('#y').val(),
$('#m').val()-1,
$('#d').val()
);
$('#date-pick').dpSetSelected(d.asString());
}
);