The Old County The Old County - 1 year ago 57
Javascript Question

Select box and getting the option label

I have a dropdown box with the following structure

<option value="">Property Type</option>
<option value="T">Terrace</option>
<option value="F">Flat</option>
<option value="S">Semi</option>
<option value="D">Detached</option>

the handle function looks like this - I can obtain the value of the dropdown with --- but I need to obtain the label - so instead of "F" I need "Flat".

handlePropertyTypeChange: function(e) {

-- I have tried obtaining it using

Answer Source


var el = document.getElementByName('prototypetype');
var text = el.options[el.selectedIndex].innerHTML;

With JQuery:

$('select option:selected').text();

With React event:

var index =;[index].text

See the demo from @Dhiraj Bodicherla: Get selected option text using react js?