0

I am currently using a play code environment, and I need to find the value of the id of the option selected.

function func1() {
  document.getElementById("myDropdown").classList.toggle("show");
}

window.onclick = function(event) {
  if (!event.target.matches('.dropbtn')) {
    var dropdowns = document.getElementsByClassName("dropdown-content");
    var i;
    for (i = 0; i < dropdowns.length; i++) {
      var openDropdown = dropdowns[i];
      if (openDropdown.classList.contains('show')) {
        openDropdown.classList.remove('show');
      }
    }
  }
}
<div class="dropdown">
  <select id="selectFrom" class="selectOption inputOption" onchange="onChangeUnit();">
    <option value="1">Centimeters (cm)</option>
    <option value="2">Inches (in)</option>
    <option value="3">Kilometers (km)
    </option>
  </select>
Barmar
  • 741,623
  • 53
  • 500
  • 612

0 Answers0