Showing posts with label getting selected text from the html select menu. Show all posts
Showing posts with label getting selected text from the html select menu. Show all posts

Monday, October 26, 2009

How to get selected text from the dropdown ?


The below function explains how to get selected text of the drop down menu using javascript.


function getSelectedText(){
     var subText = document.getElementById("subject");
     var selectedText = subText.options[subText.selectedIndex].text
     alert(selectedText);
}
"subText.selectedIndex" gives index of the selected value, By passing that index value to array of the subtext options you will get the selected text from the drop down menu.