от 1 до 28, общие для всех месяцев.
за 29 лет мы должны сделать выбор.
787
addOption 29 when feb and leapyear
addOptions 29 30 when month with 30 days april,june,sep,nov
addOptions 29 30 31 when months with 31 days jan,march,may,july,aug,oct,dec
при повторном нажатии удалите все добавленные параметры, а затем повторно проверьте значение месяца и года, чтобы найти категорию, к которой относится месяц. GOTO 787
<script type="text/javascript">
var monthselected,yearselected,mtype=0,visited=0;
function removeOptions(){ //removes options call each time the day selector is clicked
var x=document.getElementById('dayselect');
while(x.length>29)
{ x.remove(x.length-1);}
}
function addOptions(mtype)
{ //adds options acc to mtype
//alert('initialising');
var i;
var x=document.getElementById("dayselect");
for(i=29;i<=mtype;i++)
{ var option=document.createElement("option");
option.text=i;
try
{//alert('trying');
// for IE earlier than version 8
x.add(option,x.options[null]);
}
catch (e)
{//alert('catching');
x.add(option,null);
}
}
}
function isleapyear(year){ //find if year is leap or not
if((year%4)==0)
{
if((year%100)!=0)
{
return true;
}
else return false;
}
if((year%400)==0)
{
return true;
}
else return false;
}
</script>
<html><td id="bday" >Birthday</td>
<td><select id="month" name="month" class="int" onBlur="monthselected=document.getElementById('month').value;">
<option value="00">Month</option>
<option value="01" >January</option>
<option value="02" > February</option>
<option value="03" > March</option>
<option value="04" > April</option>
<option value="05" > May</option>
<option value="06" > June</option>
<option value="07" > July</option>
<option value="08" > August</option>
<option value="09" > September</option>
<option value="10" > October</option>
<option value="11" > November</option>
<option value="12" > December</option>
</select>
<label id="year-label" class="year int">Year<select class="int" id="year" name="year" selected= onBlur="yearselected=document.getElementById('year').value;"><option value="0" >YYYY</option>
<?php for($i=2012;$i>1912;$i--){echo "<option value=\"$i\">$i</option>";} ?>
</select>
<label id="day-label" class="day int">Day<select id="dayselect" class="int" name="day" onClick=
"if(monthselected==4||monthselected==6||monthselected==9||monthselected==11)
{mtype=30;}
if(monthselected==2&&isleapyear(yearselected))
{mtype=29;}
if(monthselected==2&&!isleapyear(yearselected))
{mtype=28;}
else if(mtype==0){mtype=31;}
if(visited!=0){removeOptions();}
addOptions(mtype);
visited=1;">
<option value="0" > DD</option><?php for($i=1;$i<29;$i++){
echo "<option value=\"$i\">$i</option>";} ?>
</select>
</label>
</td>
Это то, над чем я работал сегодня.
соответствующие узлы добавляются или удаляются в событии onClick.