sandrozbinden
sandrozbinden

Reputation: 1597

JQuery datepicker allow user to set the year

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.

Upvotes: 16

Views: 51528

Answers (4)

jQuery("#date").datepicker({
    dateFormat: "dd-mm-yy",
    changeMonth: true,
    changeYear: true,
    yearRange: "-80:+00" // Use this to get the list of years you more than default range.
});

Upvotes: 2

Rokan Nashp
Rokan Nashp

Reputation: 351

You can set year and also month just putting following two lines.

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

Here date is input ID

Upvotes: 0

Sebastian
Sebastian

Reputation: 470

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"
 });

Upvotes: 24

ggzone
ggzone

Reputation: 3711

changeYear: true

already displaying a selectbox.. so whats the problem?? for manually input of the year just create own input text?

Upvotes: 17

Related Questions