dj_arnel Posted January 4, 2012 Share Posted January 4, 2012 Greetings to mjdamato! This is the code I've been looking. However, I want my Date of Birth to like the Facebook or Tagged with the additional "Month:" "Day:" and "Year:" in the selection option. Sad to say this creates a bug on the code. The number 28 is missing in the Day option. This is my code for the Birth Date form : <?php $monthOptions = '<option value="0" id="month_option">Month:</option>'; $dayOptions = '<option value="0" id="day_option">Day:</option>'; $yearOptions = '<option value="0" id="year_option">Year:</option>'; $nowYear = date("Y"); for($month=1; $month<=12; $month++){ $monthName = date("F", mktime(0, 0, 0, $month)); // F Full Month name $monthOptions .= "<option value=\"{$month}\">{$monthName}</option>\n"; } for($day=1; $day<=31; $day++){ $dayOptions .= "<option value=\"{$day}\">{$day}</option>\n"; } for($year=1930; $year<=$nowYear; $year++){ $yearOptions .= "<option value=\"{$year}\">{$year}</option>\n"; } ?> <select name="month" id="month" onchange="updateDays();"> <?php echo $monthOptions; ?> </select> <select name="day" id="day"> <?php echo $dayOptions; ?> </select> <select name="year" id="year" onchange="updateDays();"> <?php echo $yearOptions; ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/254346-date-of-birth-form-adjustment/ Share on other sites More sharing options...
Pikachu2000 Posted January 4, 2012 Share Posted January 4, 2012 Topic split from old thread . . . http://www.phpfreaks.com/forums/index.php?topic=290078.0 Quote Link to comment https://forums.phpfreaks.com/topic/254346-date-of-birth-form-adjustment/#findComment-1304158 Share on other sites More sharing options...
Adam Posted January 4, 2012 Share Posted January 4, 2012 The code should, and does, work as expected. It must be something your end that's causing the 28 to disappear.. Quote Link to comment https://forums.phpfreaks.com/topic/254346-date-of-birth-form-adjustment/#findComment-1304192 Share on other sites More sharing options...
dj_arnel Posted January 4, 2012 Author Share Posted January 4, 2012 Just to elaborate, this topic is a continuation of http://www.phpfreaks.com/forums/index.php?topic=290078.0 The complete code is this <?php $monthOptions = '<option value="0" id="month_option">Month:</option>'; $dayOptions = '<option value="0" id="day_option">Day:</option>'; $yearOptions = '<option value="0" id="year_option">Year:</option>'; $nowYear = date("Y"); for($month=1; $month<=12; $month++){ $monthName = date("F", mktime(0, 0, 0, $month)); // F Full Month name $monthOptions .= "<option value=\"{$month}\">{$monthName}</option>\n"; } for($day=1; $day<=31; $day++){ $dayOptions .= "<option value=\"{$day}\">{$day}</option>\n"; } for($year=1930; $year<=$nowYear; $year++){ $yearOptions .= "<option value=\"{$year}\">{$year}</option>\n"; } ?> <html> <head> <script type="text/javascript"> function updateDays() { //Create variables needed var monthSel = document.getElementById('month'); var daySel = document.getElementById('day'); var yearSel = document.getElementById('year'); var monthVal = monthSel.value; var yearVal = yearSel.value; //Determine the number of days in the month/year var daysInMonth = 31; if (monthVal==2) { daysInMonth = (yearVal%4==0 && (yearVal%100!=0 || yearVal%400==0)) ? 29 : 28; } else if (monthVal==4 || monthVal==6 || monthVal==9 || monthVal==11) { daysInMonth = 30; } //Add/remove options from days select list as needed if(daySel.options.length > daysInMonth) { //Remove excess days, if needed daySel.options.length = daysInMonth; } while (daySel.options.length != daysInMonth) { //Add additional days, if needed daySel.options[daySel.length] = new Option(daySel.length+1, daySel.length+1, false); } return; } </script> </head> <body> Birthdate:<br /> <select name="month" id="month" onchange="updateDays();"> <?php echo $monthOptions; ?> </select> <select name="day" id="day"> <?php echo $dayOptions; ?> </select> <select name="year" id="year" onchange="updateDays();"> <?php echo $yearOptions; ?> </select> </body> </html> As you can see, upon testing on Feb 1932 and Feb 1996 (both leap year), the number 28 is missing. Quote Link to comment https://forums.phpfreaks.com/topic/254346-date-of-birth-form-adjustment/#findComment-1304248 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.