i have made three drop downs month year day{1,2,3...}
i want only valid day gets displayed in the drop down.
i.e if jan is selected 31 is the upper limit if feb is selected 28 or 29 depending upon the year (leap or not)

var monthselected,yearselected,mtype=0,visited=0;
function reassembleDate(){
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;} 
                            removeOptions();
                           addOptions(mtype);}                          
function removeOptions(){
var x=document.getElementById('dayselect');
while(x.length>29)
    { x.remove(x.length-1);}
    }

function addOptions(mtype)
{
//alert('initialising');
var i;
for(i=29;i<=mtype;i++)
{
var x=document.getElementById("dayselect");
    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){
        if((year%4)==0)
        {
        if((year%100)!=0)
        {
        return true;
        }
        else return false;
        }
        if((year%400)==0)
            {

            return true;

            }

else return false;
}                       







<td><select  id="month" name="month" class="int" onChange="reassembleDate();" onBlur="monthselected=document.getElementById('month').value; reassembleDate();"        >
                        <option value="">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</label>
  <select class="int" id="year" name="year" onChange="reassembleDate();" onBlur="yearselected=document.getElementById('year').value; reassembleDate();"><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</label><select id="dayselect" class="int" name="day" >
<option value="0" >  DD</option>
<?php for($i=1;$i<29;$i++){echo "<option value=\"$i\">$i</option>";} ?></select>

the code works fine when there are upto two changes but after that the list of date{1,2,3...} does not change.Why is this happening?
I have tried changing dates on all events like onChange and onBlur it does not help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.