I have a datepicker on an application form. We only allow applications where the date of birth is within a certain age range. I enabled ChangeYear and set the YearRange to "-65:-16". The problems I am having are as follows:
1 - When I select a date without first selecting something in the year dropdown, I get the correct month and day, but I get 2016 as a year.
2 - Trying to fix this I set the YearRange to "n-65:n-16". That causes the year dropdown to only display the current year (2010). Even weirder is that if you select a date, you still get the correct month and day, and the year 2016.
Here is the code I use to setup the datepicker:
<script type="text/javascript">
$(document).ready(function (e) {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
$(function () {
$("#DateOfBirth").datepicker({ yearRange: '-65:-13', changeMonth: true, changeYear: true, defaultDate: '1-1-1994', dateFormat: 'mm-dd-yy' })
});
}
$(function () {
$("#DateOfBirth").datepicker({ yearRange: '-65:-13', changeMonth: true, changeYear: true, defaultDate: '1-1-1994', dateFormat: 'mm-dd-yy' })
});
});
</script>
I am hoping this is something I have done wrong, and someone can tell me what that is. Thanks for any help.
Setting a start and end date Then add both lines in the JavaScript Code box e.g. var start_date = new Date(). increment('week', 1); var end_date = new Date(). increment('week', 5);
Simply call . datepicker() on a div instead of an input. (To display the datepicker embedded in the page instead of in an overlay.) Save this answer.
By default DatePicker has standard height and width (height: '30px' and width: '143px'). You can change this height and width by using height and width property respectively.
Try using 'c' for the current year like:
$('.datepicker').datepicker({changeYear: true, yearRange : 'c-65:c+10'});
for more information view http://api.jqueryui.com/datepicker/#option-yearRange
Check your defaultDate setting. I can only see what you're describing when I change the default date to something outside of the specified year range (i.e. '1-1-2016'.) Everything else in the code you posted worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With