I found a code on how to make a dynamic dropdown list for selecting years, but I don't know how to add a default value to the dropdown, this is the code i found on
HTML looping option values in drop down list
HTML
<select id="year"></select>
JS
var start = 2018;
var end = new Date().getFullYear();
var options = "";
for(var year = start ; year <=end; year++){
options += "<option>"+ year +"</option>";
}
document.getElementById("year").innerHTML = options;
I tried like this but it doesn't work
<select id="year">
<option value=''>Year</option>
</select>
and this
var start = 2018;
var end = new Date().getFullYear();
var options = "<option value=''>Year</option>";
for(var year = start ; year <=end; year++){
options += "<option>"+ year +"</option>";
}
document.getElementById("year").innerHTML = options;
the result I want is like this
<select id="year">
<option value=''>Year</option>
<option value=''>2018</option>
<option value=''>2017</option>
</select>
anyone know how to do it ?
didn't expext there will be a lot of answers, thank you guys I'm gonna try your answer