/ Published in: PHP
Generates an options list of years for a select box, going from current year backwards through the number of years specified in the first variable.
Useful for birthday fields on signup forms.
eg. 2009, 2008, 2007, 2006 ... 1912, 1911, 1910, 1909
EDITED: Now includes option to set the initially selected value to a set number of years ago. Useful if your form is targetted at a certain age group. Will default to current year if set to '0'.
Useful for birthday fields on signup forms.
eg. 2009, 2008, 2007, 2006 ... 1912, 1911, 1910, 1909
EDITED: Now includes option to set the initially selected value to a set number of years ago. Useful if your form is targetted at a certain age group. Will default to current year if set to '0'.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Number of years to go back $yearRange = 100; // Selected Age $ageLimit = 18; // Generate Options $startYear = ($thisYear - $yearRange); $selectYear = ($thisYear - $ageLimit); $selected = ""; if($year == $selectYear) { $selected = " selected"; } print '<option' . $selected . '>' . $year . '</option> '; }