Reputation: 11578
how can i show or display only years in JQuery UI Calendar? I need to do a dropdown list with years without taking care the month, just years.
Thanks in advance
Upvotes: 3
Views: 16874
Reputation: 11
var i,yr,now = new Date();
for (i=0; i<10; i++) {
yr = now.getFullYear()+i; // or whatever
$('#select-year').append($('<option/>').val(yr).text(yr));
};
This function works very well but it has some error
Upvotes: 1
Reputation: 434
If you want a jquery UI datepicker which shows only the year, try this:
stepMonths: 12,
monthNames: ["","","","","","","","","","","",""]
Result: no month name is shown.
I also used this to hide the calendar-part of the datepicker:
<style>.ui-datepicker-calendar { display: none; } </style>
Upvotes: 2
Reputation: 92893
$( "#datepicker" ).datepicker({
changeMonth: false,
changeYear: true
});
http://jqueryui.com/demos/datepicker/#dropdown-month-year
Alternatively, if you just want a list of years, you can generate it without jQueryUI:
var i,yr,now = new Date();
for (i=0; i<10; i++) {
yr = now.getFullYear()+i; // or whatever
$('#select-year').append($('<option/>').val(yr).text(yr));
};
Upvotes: 2