<form name="regForm" action="checkReg.jsp" method="post">
<select name="birthYear" onchange="changeDate();"><!--注意:考虑到润年的关系,这里也要加上onchange事件-->
<%
String txt=new string("");
txt="";
for(int i=1940;i<2046;i++){
   txt+="<option value=\""+i+"\">"+i+"年</option>"
}
out.print(txt);
%>
</select>
<select name="birthMonth" onchange="changeDate();">
<%
txt="";
for(int i=1;i<13;i++){
   txt+="<option value=\""+i+"\">"+i+"月</option>";
}
out.print(txt);
%>
</select>
<select name="birthDay">
</select>
</form>
<script language="javascript">
function changeDate(){
  var days = getMonthDays(document.regForm.birthYear.value,document.regForm.birthMonth.value); //取得当前月应该有多少天
  var obj = document.regForm.birthDay;  //取得日期Select容器
  var lastValue = obj.value;  //记录用户选择的值
  if(lastValue*1 > days)lastValue = days;
  if(!lastValue)lastValue=1;
  while(obj.options.length>0) //清空日期选择框
obj.options.remove(0);
  for (var i=1; i<=days; i++)  //添加日期选项
obj.options.add(new Option(i+"日",i));
  obj.value = lastValue;  //恢复用户选择的值
}//获取指定月份的天数
function getMonthDays(year,month)
{
var d = new Date(year,month-1,1);
var returnValue = 0;
for(;d.getMonth()==month-1;d.setTime(d.getTime()+86400000))returnValue++;
return returnValue;
}
changeDate(); //初始化日期选择框
</script>