Jump to content

change drop down list from current to past years to current to future years


Lisa23

Recommended Posts

Hi i have this drop down list current the year is 2010 and downwards but i want to change the list to 2010 upwards u can notice on the 50-- so shows current year minus so current is 2010 to 61 how can i change 2010 to 2030 or sunfin??

 

echo '<select name="year_of_birth">',"\n";
    $year = date("Y");
    for ($i = $year;$i > $year-50;$i--) {
      if($i == $thisYear) { 
        $s = ' selected'; 
      } else { 
        $s='';
      }
      echo '<option value="' ,$i, '"',$s,'>' ,$i, '</option>',"\n";
    }
  echo '</select>',"\n";

Link to comment
Share on other sites

$year = range(2010, 2061); // creates array with all values from 2010 through 2061
echo '<select name="year_of_birth">',"\n";
foreach( $year as $v ) {
     echo "<option value=\"$v\"";
          if( $v == $thisYear ) {
               echo ' selected="selected"';
          }
     echo ">$v</option>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.