Reputation: 2319
I have to show a datepicker for date of birth, since the year range will be about 80 years I am using the following code.
$('#<%=txtdob.ClientID%>').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
yearRange: 'c-100:c-20'
});
it is working but whenever we change the year range it goes back 100 years!. I think I am missing something . Fiddler code is--> http://jsfiddle.net/MCheP/ Please help..
Edit: when textbox is clicked calender show up. but when I change year from 1914 to say 1920 it shows 1820 instead of 1920.
Upvotes: 1
Views: 881
Reputation: 2361
$( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
yearRange: '-100:-20',
defaultDate: '-100y'
});
Demo http://jsfiddle.net/MCheP/6/
Upvotes: 1
Reputation: 318182
Why is there a c
in there ?
$("#datepicker").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
yearRange: '-100:-20',
defaultDate: '-100y'
});
the leading c
sets the range relative to the selected date, so when you select a date, it sets the range back another 100 years from that date. To keep the range static you remove the c
Upvotes: 1
Reputation: 144
$( "#datepicker" ).datepicker({ changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy', minDate: "-100Y", maxDate: "-20Y" });
Upvotes: 0
Reputation: 15767
please see the documentation
http://api.jqueryui.com/datepicker/#option-yearRange
the actual syntax/example is
$( ".selector" ).datepicker({ yearRange: "2002:2012" });
You can also use it like this also
yearRange: "-100:-20"
Upvotes: 0