populating select options dynamically javascript
html, javascript
Solution
Quick and dirty, this will do the trick:
window.onload = function(){
var year = (new Date()).getFullYear(), select = document.getElementById("year"), option = null, next_year = null;
for(var i = 0; i <= 10; i++) {
option = document.createElement("option");
next_year = parseInt(year, 10) + i;
option.value = next_year;
option.innerHTML = next_year;
select.appendChild(option);
}
};
Problem
I want to have option for select list dynamically. I want to populate select list for year values dynamically using java script. It should be current year to next 10 years as drop down, any idea? ``` <form action="something"> some other fields <select id="year"> </select> </form> ```