I have two drop down menus with the id validKeys1
and validKeys2
, I'm trying to populate the drop downs from an array using the javascript code below, but it will only populate validKeys2
. How do I use the same piece of javascript on multiple IDs?
var validKeys1 = document.getElementById("validKeys1");
var validKeys2 = document.getElementById("validKeys2");
for(var i = 0; i < validCoursesKeys.length; i++) {
var opt = validCoursesKeys[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
validKeys1.appendChild(el);
validKeys2.appendChild(el);
}