I know there are multiple posts on this topic, and I have followed them to get to this point. However I cannot seem to get my dropdown to populate with my options. Maybe I have been staring at it for too long... any help is appreciated.
var fromYear = document.getElementById("from-year");
var toYear = document.getElementById("to-Year");
var years = ["2019","2020","2021","2022","2023","2024","2025","2026"];
for(var i = 0; i < years.length; i++) {
var opt = years[i];
var el = document.createElement("year");
el.textContent = opt;
el.value = opt;
fromYear.appendChild(el);
toYear.appendChild(el);
}
<div>
<div class = "date-from">
<select id="from-year">
<option>from: Year</option>
</select>
</div>
<div class = "date-to">
<select id="to-year">
<option>to: Year</option>
</select>
</div>
</div>
{% load static %}
<script src="{% static 'buildstats/buildStats.js' %}"></script>
I have other javascript in this .js file, and it is working correctly and populating elements on the DOM. It is just this options list that does not want to populate. The only item in the options list that populates is the default value I gave it in the HTML doc.
<head>or in the<body>?var el = document.createElement("year");-yearisn't a valid HTML tag, I don't know if this is why the script is falling over, but surely it should be"option"?document.getElementById("to-Year")notice the capitalisedYear.