Ok, I have most of it working, figured a lot of it out on my own.
I have this in the header of the page:
- Code: Select all
//year
var d = new Date();
var this_year = d.getFullYear();
var cent_year = this_year-100;
//month
var month = new Array();
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "Apr";
month[4] = "May";
month[5] = "Jun";
month[6] = "Jul";
month[7] = "Aug";
month[8] = "Sep";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";
//day
function checkData()
{
var yr=document.getElementById("year").value;
var leapyear = 0;
if ((parseInt(yr)%4) == 0)
{
if (parseInt(yr)%100 == 0)
{
if (parseInt(yr)%400 != 0)
{
alert("Not Leap");
leapyear = 0;
}else{
alert("Leap Year");
leapyear = 1;
}
}
if (parseInt(yr)%100 != 0)
{
alert("Leap");
leapyear = 1;
}
}
if ((parseInt(yr)%4) != 0)
{
alert("Not Leap");
leapyear = 0;
}
}
And this in the body:
- Code: Select all
<div>
<label>Bithday:
<label for="year">Year</label>
<select id="year" onChange="checkData()">
<script type="text/javascript">
for(i=this_year; i>=cent_year ; i--) {
document.write("<option value=" + i +">" + i +" </option>");
}
</script>
</select>
<label for="month">Month</label>
<select id="month" name="month" >
<script type="text/javascript">
for(j=0; j<=11 ; j++) {
document.write("<option value=" + month[j] +">" + month[j] +" </option>");
}
</script>
</select>
<label for="day">Day</label>
<select id="day">
<script type="text/javascript">
// I need the code to work here...
</script>
</select>
</div>
So I have it set up so that when the user selects the year they were born, it checks to see that it is or isn't a leapyear.
I'm having trouble figuring out a way to do two things:
1) Depending on the month, the date dropdown will display the correct number of days. Jan 31, Feb 28, March 31... etc
2) If it is a leapyear, I need Feb to have 29 days instead of 28.
Any tips to get this to work?
I've been stuck for a few hours now.
Thanks
