javascript select option based on text code example
Example 1: how to get text from select tag in javascript
<select id="box1" onChange="myNewFunction(this);">
<option value="98">dog</option>
<option value="7122">cat</option>
<option value="142">bird</option>
</select>
<script>
function myNewFunction(sel) {
alert(sel.options[sel.selectedIndex].text);
}
</script>
Example 2: 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;
}
}