Date Of Birth - Drop Down Box - Function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Date Of Birth - Drop Down Box - Function

    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.

    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(000$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

    Usage:
    PHP Code:
    echo '<form action="index.php">';
    echo 
    dateOfBirth(29,04,1985);
    echo 
    '<input type="submit" value="Update Birthday"/></form>'
    Last edited by something else; 23.04.11, 11:06. Reason: Made Code Faster

    #2
    Thats PHP mktime() function logically used. Thanks, this is really a code space savior
    tinyurl.com/earnbymobile
    Easy earning for Indians
    ---------------------
    Alternative mobile advertising network .. Minimum 100 USD pay / NET15 pay cycle, Good Brand, Best targeting for Android
    goo.gl/6vub3

    Comment

    Working...
    X