可能重复:
在 JavaScript 中计算年龄
I have create form which includes Birth date,Current Date,Age text boxes,current date display by default in text box,when choose birth date I want calculate age & display it into age text box.. My Java script code:
<html>
<head>
<script language="javascript">
function aaa()
{
date= new Date();
var d = date.getDate();
var m= date.getMonth()+1;
var y= date.getFullYear();
document.getElementById('ddd').value=m + '/' + d + '/' + y;
}
function display()
{
var a = document.getElementById('eee').getDate.value;
var b = document.getElementById('eee').getMonth.value;
var c = document.getElementById('eee').getFullYear.value;
//var aa= document.getElementById('eee').(this).('getDate').value;
var e= y - c;
{
document.write("Ans="+e);
}
alret(e);
}
</script>
</head>
<body onload="aaa();">
<form name="xyz" method="post">
CurrentDate:<input type="text" name="ddd" id="ddd" readonly="readonly">
BirthDate:<input type="date" name="eee" id="eee">
Age:<input type="text" name="age" id="age">
<input type="submit" name="submit" value="submit" onClick="display();">
</form>
</body>
</html>