Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery datepicker years shown

With the jQuery datepicker, how does one change the year range that is displayed? On the jQuery UI site it says the default is "10 years before and after the current year are shown". I want to use this for a birthday selection and 10 years before today is no good. Can this be done with the jQuery datepicker or will I have to use a different solution?

link to datepicker demo: http://jqueryui.com/demos/datepicker/#dropdown-month-year

like image 477
John Boker Avatar asked Nov 06 '08 17:11

John Boker


People also ask

How do I display only the year in datepicker?

I will suggest to add formate on datepicker as "YYYY" so it will only show years inside it.

How do you change the year on a date picker?

There's a changeYear property on the datepicker that you can set to true . This will render a select list from which you can choose the year you'd like. Save this answer.

What is datepicker in jQuery?

A date-picker of jQuery UI is used to provide a calendar to the user to select the date from a Calendar. This date picker usually connected to a text-box so user selection of date from the calendar can be transferred to the textbox.


2 Answers

If you look down the demo page a bit, you'll see a "Restricting Datepicker" section. Use the dropdown to specify the "Year dropdown shows last 20 years" demo , and hit view source:

$("#restricting").datepicker({      yearRange: "-20:+0", // this is the option you're looking for     showOn: "both",      buttonImage: "templates/images/calendar.gif",      buttonImageOnly: true  }); 

You'll want to do the same (obviously changing -20 to -100 or something).

like image 188
Shog9 Avatar answered Oct 13 '22 06:10

Shog9


Why not show the year or month selection boxes?

$( ".datefield" ).datepicker({     changeMonth: true,     changeYear: true,     yearRange:'-90:+0' }); 
like image 39
Plippie Avatar answered Oct 13 '22 05:10

Plippie