How to get Javascript Select box's selected text

Aajahid picture Aajahid · Jul 3, 2010 · Viewed 231.4k times · Source

This things works perfectly

<select name="selectbox" onchange="alert(this.value)">

But I want to select the text. I tried in this way

<select name="selectbox" onchange="alert(this.text)">

It shows undefined. I found how to use DOM to get text. But I want to do this in this way, I means like using just this.value.

Answer

Delan Azabani picture Delan Azabani · Jul 3, 2010
this.options[this.selectedIndex].innerHTML

should provide you with the "displayed" text of the selected item. this.value, like you said, merely provides the value of the value attribute.