Answers for "document.createelement options list"

0

document.createelement options list

document.getElementById('generate').onclick = function() {
 
  var values = ["dog", "cat", "parrot", "rabbit"];
 
  var select = document.createElement("select");
  select.name = "pets";
  select.id = "pets"
 
  for (const val of values) {
    var option = document.createElement("option");
    option.value = val;
    option.text = val.charAt(0).toUpperCase() + val.slice(1);
    select.appendChild(option);
  }
 
  var label = document.createElement("label");
  label.innerHTML = "Choose your pets: "
  label.htmlFor = "pets";
 
  document.getElementById("container").appendChild(label).appendChild(select);
}
Posted by: Guest on June-11-2020

Code answers related to "document.createelement options list"

Code answers related to "Javascript"

Browse Popular Code Answers by Language