Leandro Bardelli
Leandro Bardelli

Reputation: 11578

Display only years in JQuery UI Calendar

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

Answers (3)

guest
guest

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

  1. It display year 3 times.
  2. When we select second time the data display with previous selected data.

Upvotes: 1

OlleMattsson
OlleMattsson

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

Blazemonger
Blazemonger

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

Related Questions