Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 387
sandrozbinden Avatar asked Dec 07 '11 09:12

sandrozbinden


People also ask

How do I change date format in Datepicker?

Here's one specific for your code: var date = $('#datepicker'). datepicker({ dateFormat: 'dd-mm-yy' }). val();

How can change date format in jQuery UI Datepicker?

By default, the date format of the jQuery UI Datepicker is the US format mm/dd/yy, but we can set it to a custom display format, eg: for European dates dd-mm-yyyy and so on. The solution is to use the date picker dateFormat option.

What is minDate and maxDate in jQuery Datepicker?

If you like to restrict access of users to select a date within a range then there is minDate and maxDate options are available in jQuery UI. Using this you can set the date range of the Datepicker. After defining these options the other days will be disabled which are not in a defined range.


1 Answers

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.
});
like image 99
Harshadkumar Prajapati Avatar answered Oct 17 '22 16:10

Harshadkumar Prajapati