Javascript - get HTML drop down label

Javascript08 Nov 2010

Normally when you're using drop downs, you can get the selected value through Javascript. Did you need of the selected drop down label previously? Here I'm going to give you a small function with which you can get it.


<SCRIPT type="text/javascript">
//Function to get the drop down label for the given index
function getDropDownLabel(element)
{
if($(element))
{
var obj=$(element);
return obj[obj.selectedIndex].firstChild.nodeValue;
}
}
function $(element)
{
return document.getElementById(element);
}
</SCRIPT>


You can give a try with below example...





This program has been tested on all the major browsers like IE >= 6.0, Mozilla >= 2.0 and Google chrome...