I have this PHP Code that is populating values in a SELECT box for the previous 10 years and the next 10 years.
<select name="fromYear"';
$starting_year =date('Y', strtotime('-10 year'));
$ending_year = date('Y', strtotime('+10 year'));
for($starting_year; $starting_year <= $ending_year; $starting_year++) {
echo '<option value="'.$starting_year.'">'.$starting_year.'</option>';
}
echo '<select>
how can I make it automatically select the current year?
Change your echo to:
Please use the code above for loop, instead of yours.
Check the year with current year and make it selected.
You should use the selected attributed