Answers for "javascript change select options dynamically"

0

javascript change select options dynamically

function getType() {
  var x = document.getElementById("food").value;
  var items;
  if (x === "fruit") {
    items = ["Apple", "Oranges", "Bananas"];
  } else {
    items = ["Eggplants", "Olives"]
  }
  var str = ""
  for (var item of items) {
    str += "<option>" + item + "</option>"
  }
  document.getElementById("pickone").innerHTML = str;
}
document.getElementById("btn").addEventListener("click", getType);
Posted by: Guest on November-10-2020

Code answers related to "javascript change select options dynamically"

Code answers related to "Javascript"

Browse Popular Code Answers by Language