Answers for "js get text select option"

1

get text of selected option js

var sel = document.getElementById("box1");
var text= sel.options[sel.selectedIndex].text;
Posted by: Guest on June-22-2021
0

how to get text from select tag in javascript

<select id="box1" onChange="myNewFunction(this);">
  <option value="98">dog</option>
  <option value="7122">cat</option>
  <option value="142">bird</option>
</select>
<script>
  function myNewFunction(sel) {
  alert(sel.options[sel.selectedIndex].text);
}
</script>
Posted by: Guest on May-27-2021

Code answers related to "js get text select option"

Browse Popular Code Answers by Language