Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
78
rated 0 times [  85] [ 7]  / answers: 1 / hits: 16446  / 9 Years ago, sat, april 4, 2015, 12:00:00

I'm new to this datepicker and I don't know how to get the month and year string on change events changeMonth and changeYear.
Here is a link to the plugin: https://github.com/eternicode/bootstrap-datepicker



The issue is that onchange captures only the transition from months to years. I am only able to get the day/date of the selected date, and nothing is selected during transition.



I tried to grab text from the div, but I am always one selection too late. How can I get the month and year of the value that is selected after a transition.



To clarify:
getYear() when we see all 12 months after changing from the decade view



getMonth() when we see days after the month view



Heres my fiddle: http://jsfiddle.net/vj3cdzbc/2/


More From » jquery

 Answers
12

Get month:



 $(#datepicker).datepicker().on('changeMonth', function(e){ 
var currMonth = new Date(e.date).getMonth() + 1;
});


Get year



 $(#datepicker).datepicker().on('changeYear', function(e){ 
var currYear = String(e.date).split( )[3];
});

[#67199] Thursday, April 2, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ignacio

Total Points: 467
Total Questions: 128
Total Answers: 79

Location: Luxembourg
Member since Tue, Mar 14, 2023
1 Year ago
ignacio questions
;