user2935177 user2935177 - 8 months ago 13
Javascript Question

to generate years automatically in javascript dropdown

I created javascript that generates years used in my dropdown menu. I want to display current year and future years automatically. Does anyone know how to implement this?

<select id="selectElementId"></select>

var min = 2012,
max = 2021,
select = document.getElementById('selectElementId');

for (var i = min; i<=max; i++){
var opt = document.createElement('option');
opt.value = i;
opt.innerHTML = i;


Use Date.getFullYear. Example:

var min = new Date().getFullYear(),
    max = min + 9