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>
<script>
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;
select.appendChild(opt);
}
</script>
Use Date.getFullYear
. Example:
var min = new Date().getFullYear(),
max = min + 9
Fiddle: http://jsfiddle.net/t8fdh/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With