JQuery datepicker allow user to set the year

sandrozbinden picture sandrozbinden · Dec 7, 2011 · Viewed 36.1k times · Source

I am using the datepicker jquery plugin with the settings below.

$("#date").datepicker({
    showButtonPanel: true,
    changeMonth: true,
    changeYear: true,
    showOtherMonths: true,
    selectOtherMonths: true 
});

Now what i want to do is allowing the user to set the year. I mean by manual changing the input of the selection drop down.

Is there any setting to do that ?

The reason I would like to do that is because I don't know, if the user is selecting a date from the year 1920 or 2220 or what ever year. So I don't have a good default date value. And the dropdown interface isn't that userfriendly if you have to click 20 times to get from the year 2000 to the year 1600.

Edit: What I want to do is the "Show unlimited years:" from keith-wood.name/datepick.html#monthyear. Is there anything similar with the standard jquery datepicker. I can't find the setting yearRange: 'any' in the jquery datepicker documentation.

Answer

Sebastian picture Sebastian · Feb 5, 2015

You can specify a range of years by adding

yearRange: "1930:2010"

to your attributes. For example:

 $( "#datepicker" ).datepicker({
     changeMonth: true,
     changeYear: true,
     yearRange: "1930:2010"
 });