Here a drop box function i made for getting date of birth
it saves having loads of days/months/years wrote on a page and also can select the last date entered if needed.
Usage:
it saves having loads of days/months/years wrote on a page and also can select the last date entered if needed.
PHP Code:
function dateOfBirth($day,$month,$year)
{
//Day
$age = 'Dob: <select name="day">';
for ($i = 1; $i <= 31; $i++) {
if($day==$i) $sel=' selected="selected"'; else $sel='';
$age .= '<option value="'.$i.'"'.$sel.'>'.$i.'</option>';
}
$age .= '</select>';
//Month
$age .= '<select name="month">';
for ($i = 1; $i <= 12; $i++) {
$name = date( 'F', mktime(0, 0, 0, $i) );
if($i<10) $i = '0'.$i;
if($month==$i) $sel=' selected="selected"'; else $sel='';
$age .= '<option value="'.$i.'"'.$sel.'>'.$name.'</option>';
}
$age .= '</select>';
//Year
$age .= '<select name="year">';
for ($i = date("o"); $i >= date("o")-100; $i--) {
if($year==$i) $sel=' selected="selected"'; else $sel='';
$age .= '<option value="'.$i.'"'.$sel.'>'.$i.'</option>';
}
$age .= '</select><br/>';
return $age;
}
PHP Code:
echo '<form action="index.php">';
echo dateOfBirth(29,04,1985);
echo '<input type="submit" value="Update Birthday"/></form>';
Comment