A very common feature of
Writing and maintaining these long list of options/years can be very monotonous via plain HTML.
forms
is the dropdown <select>
box, commonly using a range of years as the options.Writing and maintaining these long list of options/years can be very monotonous via plain HTML.
This following codebyte generates a simple
select
box, with an <option>
for each year based on some basic arguments.
Change
$currently_selected
to be the option you want as the top/default option of the select box.$earliest_year
to be the lowest year you want the range to start at.$latest_year
to be the highest year you want your range to go to. <?php
$currently_selected = date('Y');
$earliest_year = 1950;
$latest_year = date('Y');
print '<select>';
foreach ( range( $latest_year, $earliest_year ) as $i ) {
print '<option value="'.$i.'"'.($i === $currently_selected ? ' selected="selected"' : '').'>'.$i.'</option>';
}
print '</select>';
?>
0 comments:
Post a Comment