how to get selected option text in javascript code example
Example 1: get selected text js
window.getSelection().toString()
Example 2: get selected text of html dropdown in javascript
var e = document.getElementById("selectElementID");
var value=e.options[e.selectedIndex].value;
var text=e.options[e.selectedIndex].text;
Example 3: javascript select option based on text
var textToFind = 'Google';
var dd = document.getElementById('MyDropDown');
for (var i = 0; i < dd.options.length; i++) {
if (dd.options[i].text === textToFind) {
dd.selectedIndex = i;
break;
}
}