KPM KPM - 5 months ago 13
Javascript Question

JQuery DatePicker Default Date 18 years ago

I'm trying to get my jquery datepicker to default to open on 18 years in the past (user must be 18 or over to use app) and I don't want them to be able to select any date that isn't 18 years or more in the past. I have this code but I can't get it to work apart from showing the default todays date. Any help would be appreciated. Thanks.

<link rel="stylesheet" type="text/css" href="css/datepicker.css">
<script type="text/javascript" src="js/bootstrap-datepicker.js"></script>
<script type="text/javascript">
$("#datepicker").datepicker("setDate",'1998-01-01');
$(document).ready(function() {

$('#datepicker').datepicker().on('changeDate', function(ev){
$(this).datepicker('hide');
});
});
</script>

Answer

Create the datepicker by datepicker method and setDate

 $( "#datepicker" ).datepicker();
$("#datepicker").datepicker('setDate','01/01/1998');

http://codepen.io/nagasai/pen/kXyoqb