Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  2] [ 2]  / answers: 1 / hits: 25623  / 8 Years ago, wed, september 21, 2016, 12:00:00

I have the following Datepicker on my website.



As you can see from the example they have, it only goes as back as 2006 and as forward as 2026 on the year. I need the year to go back a lot further, how would I accomplish this?



Here is my code:



<script>
$(function() {
$(#passenger_dob).datepicker({ changeMonth: true, changeYear: true, dateFormat: dd/mm/yy }).val()
});
</script>

More From » jquery

 Answers
13

Use the yearRange option to set the years you want do display:



$(#passenger_dob).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: dd/mm/yy,
yearRange: -90:+00
});


the yearRange options can be hard-coded, or, as in my example, a range can be used relative to the current date. The options I've used mean earliest year displayed is 90 years before current year and maximum year displayed is equal to current year.



N.B. As noted in the docs, this merely affects the options displayed in the dropdown by default, it doesn't place any restriction on the dates which the user can actually enter/select.



See http://api.jqueryui.com/datepicker/#option-yearRange for more details.


[#60652] Sunday, September 18, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
miles

Total Points: 256
Total Questions: 111
Total Answers: 104

Location: Benin
Member since Fri, Mar 24, 2023
1 Year ago
;