How to get the text of a selected item in a select control?

icn picture icn · Apr 27, 2010 · Viewed 29k times · Source
 <select name="DropList" id="serverDropList"> 
  <option selected="selected" value="2">server1:3000</option> 
  <option value="5">server3:3000</option> 
 </select> 

i know in prototype i can get value by $('serverDropList').value but how can i get "server1:3000" ?

Answer

multikulinaria picture multikulinaria · Sep 12, 2011

If you are using Prototype, you may use:

var text = $('serverDropList')[$('serverDropList').selectedIndex].text;