add years as options to select dropdown

add the years as dropdown items between a range of years with javascript

document ready js only version


<select id="years" name="years">
    <option value="-1">&nbsp;</option>


// this also needs a document ready check, otherwise it cant find the element to add the years to.
document.addEventListener("DOMContentLoaded", function(event) { 
  // add dom loaded stuff

var selectBox = document.getElementById('years');
for (var i = 2030; i >= 1980; i--) {
    var option = document.createElement('option');
    option.value = i;
    option.innerHTML = i;

Other Items in javascript

No Items Found.

Add Comment
Type in a Nick Name here
Page Views

This page has been viewed 233 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
โ€œWe ought to take outdoor walks in order that the mind may be strengthened and refreshed by the open air and much breathing.".