Item Label of a Dropdown

C

Crescionini Sascha

hello ng

is there a way to get the selected item-label (not value)
of a dropdown-element using js?

any idea?

greets
sascha
 
V

Vjekoslav Begovic

One way is shown below:
<html>
<head>
<script type="text/javascript">
function testit(selobj){
var selectedOption = selobj[selobj.selectedIndex];
var label = selectedOption.firstChild.nodeValue;
alert(label)
}
</script>
</head>
<body>
<select id="sel1" onchange="testit(this)">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>

</body>
</html>
 
L

Lasse Reichstein Nielsen

Crescionini Sascha said:
is there a way to get the selected item-label (not value)
of a dropdown-element using js?

selectRef.options[selectRef.selectedIndex].text

An option element has two properties: value and text.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top