showing results for - "document createelement options list"
Giorgia
22 Feb 2020
1document.getElementById('generate').onclick = function() {
2 
3  var values = ["dog", "cat", "parrot", "rabbit"];
4 
5  var select = document.createElement("select");
6  select.name = "pets";
7  select.id = "pets"
8 
9  for (const val of values) {
10    var option = document.createElement("option");
11    option.value = val;
12    option.text = val.charAt(0).toUpperCase() + val.slice(1);
13    select.appendChild(option);
14  }
15 
16  var label = document.createElement("label");
17  label.innerHTML = "Choose your pets: "
18  label.htmlFor = "pets";
19 
20  document.getElementById("container").appendChild(label).appendChild(select);
21}
22