poo
poo

Reputation: 1115

Getting text of html select in javascript?

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?

Upvotes: 0

Views: 120

Answers (2)

Graza
Graza

Reputation: 5050

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

Upvotes: 0

Matt
Matt

Reputation: 75327

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

this.options[this.selectedIndex].text

Upvotes: 2

Related Questions