0

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?
    });
});
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
  • Could you create a code snippet? That will be easier for you to get answer. – pritesh Mar 13 '16 at 02:31
  • I have edited your question: mainly fixed the code indentation and shortened the title a bit. I've made the datepicker tag more specific (now bootstrap-datepicker). – Benjamin W. Mar 13 '16 at 03:34

0 Answers0