phpformsselected

php generated option selected by default


I'm probably blind to my own mistake again, but why doesn't 2011 become the default selected year? (The -- are for debugging, they show up that the if statement works correctly.)

for($year=1900;$year<=2050;$year++) {
 if ($year==date("Y"))
   echo "<option value='".$year."' selected='selected'>--".$year."</option>";
 else
   echo "<option value='".$year."'>".$year."</option>";
}

The selected='selected' should just work. (link) So it is either a stupid mistake(i really don't see one) or some effect from php..

UPDATE: found the problem.. the ftp didn't overwrite the file properly. Now it works. Thanks for the fast help, when these things happen I always start doubting my own sanity. (cant send this as answer because i have a low rep)


Solution

  • Are you checking the generated HTML? Maybe this code works well (it seems it does), but the problem is in select, or in another place.