Thursday, September 2, 2010

JavaScript Age Calculation

function IsValidAge(agelimit) {
var month = document.getElementById("ddlMonth").selectedIndex-1;
var day = $("#ddlDay option:selected").val();
var year = $("#ddlYear option:selected").val();
var Birthdate = new Date(year, month, day);
var Today = new Date();
var diff = new Date(Today - Birthdate);
var days = diff / 1000 / 60 / 60 / 24 / 365.25;
var age = Math.round(days);
return age > agelimit ? true : false;
}