I want to calculate an age based on the user's input on datepicker (I used Bootstrap datepicker) and output it to an age text field.
I tried searching through it, but I've got no luck. My date format is in yyyy-mm-dd
.
Here is my HTML for datepicker and age text field.
<label for="bday">Birthday:
<div id="datepicker" class="input-group date" style="width:200px;">
<input id="dob" name="date" class="form-control" type="text" />
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</label>
<label for="age">Age
<input class="form-control" type="text" id="myage" style="width:200px;" />
</label>
And here is the Javascript:
$(function () {
$('#dob').datepicker({
format: "yyyy-mm-dd",
autoclose: true,
}) .on('changeDate',function(event){
// compute age here.. I think?
});
});