Edit This Code:
<!DOCTYPE html>
<html>
<body>

<form>
  <select id="mySelect">
    <option id="apple">Apple</option>
    <option id="orange">Orange</option>
    <option id="pineapple">Pineapple</option>
    <option id="banana">Banana</option>
  </select>
</form>

<p>Click the button to display the text of the option element with id="orange" in the drop-down list.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("mySelect").options.namedItem("orange").text;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy