Reputation: 13
how i can get the text selected from select tag?
<select id="51" class="toque">
<option value="1">Save</option>
<option value="2">Delete</option>
</select>
I want to get the text between option tag (Save or Delete).
Upvotes: -1
Views: 5024
Reputation: 13
Using addEventListener(), we can get the text as well:
let selectText = document.getElementById("51");
selectText.addEventListener("change", (event) => {
console.log(selectText.options[selectText.selectedIndex].text);
});
Upvotes: 0
Reputation: 467
var sel = document.getElementById("51");
var text= sel.options[sel.selectedIndex].text;
Upvotes: 5