How can I get the selected item's value and text in JavaScript?
This is my combobox:
<select size="1" id="fTerminalType" name="fTerminalType">
<option value="AP">Airport</option>
<option value="PT">Port</option>
<option value="BS">Bus</option>
<option value="TR">Train</option>
</select>
My JavaScript is like this:
var TerminalType = document.getElementById("fTerminalType").value;
Here I can get the value of the combobox. But how can I get the text of the selected value? For example if value was "BS"
, I need the text "Bus"
.
var t = document.getElementById("fTerminalType");
var selectedText = t.options[t.selectedIndex].text;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With