Age Calculator
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">
<input type="date" class="span8" name="birthdate" id="pick" required="" />
<div>Your Age: <span id="out">0</span></div>
JavaScript
function getAge(birthday) {
var today = new Date();
var thisYear = 0;
if (today.getMonth() < birthday.getMonth()) {
thisYear = 1;
} else if ((today.getMonth() == birthday.getMonth()) && today.getDate() < birthday.getDate()) {
thisYear = 1;
}
var age = today.getFullYear() - birthday.getFullYear() - thisYear;
return age;
}
$('#pick').datepicker({
onSelect: function(dateText, inst) {
$('#out').html(getAge(new Date(dateText)));
},
maxDate: +0
});