I want to create a drop down menu of month:, day:, and year. The difficulty with this one is that i dont know whether to make this a dynamic menu list - after all - the number of days within the day selection list depends on the month entered and also the year (in the case of a leap year)
So, can any one suggest me with this or can give a sample code..
Thanx
hi check out the code below... you will get drop down box with current month and year and the days for the particular month.
I have used 2 functions in the code .One for checking the leap year and other for populating the drop down box on body load.
Read the functions in the code and write a new function if you want to change day if users changes month or year.
And move this post to javascript forum
[html]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<script>
//to check leap year
function checkleapyear(datea)
{
datea = parseInt(datea);
if(datea%4 == 0)
{
if(datea%100 != 0)
{
return true;
}
else
{
if(datea%400 == 0)
return true;
else
return false;
}
}
return false;
}
//to populate drop drow boxex with the current month and date
function populateYearSelect()
{
d = new Date();
curr_year = d.getFullYear();
curr_month=d.getMonth();
document.getElementById('month').options[curr_month].selected=true;
for(i = 0; i < 3; i++)
{
document.getElementById('year').options[i] = new Option(curr_year-i,curr_year-i);
}
if(curr_month==0 || curr_month==2 ||curr_month==4 || curr_month==6 || curr_month==7 || curr_month==9 || curr_month===11)
{
for(i=0;i<=30;i++)
document.getElementById('day').options[i] = new Option(i+1,i+1);
}
else if(curr_month==3 || curr_month==5 ||curr_month==8 || curr_month==10)
{
for(i=0;i<=29;i++)
document.getElementById('day').options[i] = new Option(i+1,i+1);
}
if(curr_month==1)
{
var year=document.getElementById('year').value;
if(checkleapyear(year))
{ for(i=0;i<=28;i++)
document.getElementById('day').options[i] = new Option(i+1,i+1); }
else
{ for(i=0;i<=27;i++)
document.getElementById('day').options[i] = new Option(i+1,i+1);}
}
}
</script>
<body onLoad="populateYearSelect()">
<select name="year" id="year" >
</select>
<select name="month" id="month">
<option value=01>JAN</option>
<option value=02>FEB</option>
<option value=03>MAR</option>
<option value=04>APR</option>
<option value=05>MAY</option>
<option value=06>JUN</option>
<option value=07>JUL</option>
<option value=08>AUG</option>
<option value=09>SEP</option>
<option value=10>OCT</option>
<option value=11>NOV</option>
<option value=12>DEC</option>
</select>
<select name="day" id="day">
</select>
</body>
</html>
[/html]