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.


No comments: