Reputation: 4278
Non-working code:
$('#datepicker').datepicker(
{ onSelect: function(dateText, dpo){
var selectedDate = dpo.getDate();
});
From the API, I see that I can use var currentDate = $( ".selector" ).datepicker( "getDate" );
in lieu of the non-working code I posted. The onSelect
documentation states "The function receives the selected date as text and the datepickerinstance as parameters". If the date picker is one of the parameters, why is the above code incorrect?
Upvotes: 1
Views: 1226
Reputation: 30993
The inst
parameter of the onSelect
is an internal object that represent the current state of the datepicker. Normally you don't need to use it, you can use this
, it refers to the original input field.
Called when the datepicker is selected. The function receives the selected date as text and the datepicker instance as parameters. this refers to the associated input field.
Code:
$('#datepicker').datepicker({
onSelect: function (dateText, dpo) {
var selectedDate = $(this).datepicker( "getDate" );
console.log(selectedDate)
}
});
Demo: http://jsfiddle.net/IrvinDominin/Y3hR6/
Upvotes: 2