0
select.onchange = function() {
   this.value; 

}

It's easy to retrieve the value but now I need the text of the selected element. How to do it?

2 Answers 2

2

(Sorry... put .value before my edit instead of .text by accident 8-)...)

this.options[this.selectedIndex].text
Sign up to request clarification or add additional context in comments.

Comments

0
//assuming "this" is the select element
if (this.selectedIndex >= 0) {
  this.options[this.selectedIndex].text = "some text";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.