此代码用于根据使用组合框的用户的选定值计算年龄,它必须在下面提供的文本框中显示年龄。每次用户更改组合框中的选定值时,必须刷新年龄。但我当前的代码没有显示计算的年龄。
<?php
$month = date("m"); //without leading zero(o)
$year = date("Y"); //four digit format
$day = date("d");
$st_year = "1950"; //Starting Year
$month_names = array("January", "February", "March","April", "May", "June", "July", "August", "September", "October", "November", "December");
?>
<form name="Month_Year" id="Month_Year" method="post">
<select name="month" id="month">
<?php
for ($i=1; $i<=12; $i++) {
echo "<option ";
if ($i == $month) {
echo "selected=\"selected\" ";
}
echo "value=\"$i\">", $month_names[$i-1], "</option>\n";
}
?>
</select>
<select name="year" id="year">
<?php
for ($i=$st_year; $i<=$year; $i++) {
echo "<option ";
if ($i == $year) {
echo "selected=\"selected\" ";
}
echo "value=\"$i\">$i</option>\n";
}
?>
</select>
<select name="day" id="day">
<?php
for ($i=1; $i<=31; $i++) {
echo "<option> ";
if ($i == $day) {
echo "selected=\"selected\" ";
}
echo "value=\"$i\">$i</option>\n";
}
?>
</select>
// I used this code to combine the selected value in the combo box.
<?php $Convertdays = $month."/".$day."/".$year;
echo $Convertdays;
?>
<script type="text/javascript">
var birth = new Date( <?php '$Convertdays'?>);
var check = new Date();
var milliDay = 1000 * 60 * 60 * 24; // a day in milliseconds;
var ageInDays = (check - birth) / milliDay;
var ageInYears = Math.floor(ageInDays / 365 );
var age = ageInDays / 365 ;
</script>
每次我更改组合框的值时,文本框都会显示 0。假设文本框的值是 1991 年 10 月 19 日,它应该显示 21