gaston graciani
gaston graciani

Reputation: 13

How get option text from select?

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

Answers (3)

pbain
pbain

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

cantuket
cantuket

Reputation: 1592

document.getElementById('51').selectedOptions[0].text;

Upvotes: 1

Wilson Madrid
Wilson Madrid

Reputation: 467

var sel = document.getElementById("51");
var text= sel.options[sel.selectedIndex].text;

Upvotes: 5

Related Questions