I'm trying to get the "shown" month and year after hitting the "next" and "previous" links on the left and right of the date picker header.
Currently I'm using to get the month:
var selectedMonth = $('#calendar').datepicker('getDate').getMonth() + 1;
but it only returns the current month, not the shown month that es with clicking "next" or "prev".
EDIT
I added the onChangeMonthYear
option with the datepicker in the function i have
function getDates() {
var selectedMonth = $('.ui-datepicker-month').text();
var selectedYear = $('.ui-datepicker-year').text();
}
still this just states the current date.
EDITED Again
the above worked just needed to set a delay :]
I'm trying to get the "shown" month and year after hitting the "next" and "previous" links on the left and right of the date picker header.
Currently I'm using to get the month:
var selectedMonth = $('#calendar').datepicker('getDate').getMonth() + 1;
but it only returns the current month, not the shown month that es with clicking "next" or "prev".
EDIT
I added the onChangeMonthYear
option with the datepicker in the function i have
function getDates() {
var selectedMonth = $('.ui-datepicker-month').text();
var selectedYear = $('.ui-datepicker-year').text();
}
still this just states the current date.
EDITED Again
the above worked just needed to set a delay :]
Share Improve this question edited Feb 23, 2013 at 21:55 Matt asked Feb 23, 2013 at 19:29 MattMatt 1051 gold badge1 silver badge8 bronze badges1 Answer
Reset to default 6$.datepicker('getDate')
only returns the selected date of the datepicker, not the month that is currently being shown.
What you're looking for is to bind a function to onChangeMonthYear
. Docs here
Example:
$('#calendar').datepicker('option', 'onChangeMonthYear', function(year, month) { var selectedMonth = month })