Mega Code Archive

 
Categories / JavaScript DHTML / Form Control
 

Return the selected option as text in option

<html> <head> <script type="text/javascript"> function getText(){     var x=document.getElementById("aSelectControl")     alert(x.options[x.selectedIndex].text) } </script> </head> <body> <form> Select your favorite language: <select id="aSelectControl">   <option>Java</option>   <option>Perl</option>   <option>PHP</option> </select> <br><br> <input type="button" onclick="getText()" value="Show text of selected language"> </form> </body> </html>