Dynamic Select Year List Script HTML Form Elements
Learn to program dynamic year select lists in HTML forms to avoid the need to write up to 100 lines in your HTML. The JavaScript loop will write the options for you in a for loop. We can do this easily because years are numeric and incremental. Adding the final year dynamically allows you to die as the programmer but still appear as if you are still updating your form every year.
<!DOCTYPE html>
<html>
<body>
<select id="year" name="year">
<script>
var myDate = new Date();
var year = myDate.getFullYear();
for(var i = 1900; i < year+1; i++){
document.write('<option value="'+i+'">'+i+'</option>');
}
</script>
</select>
</body>
</html>