Home > Article > Web Front-end > How to get the "selected value" and "selected text" of a standard drop-down box using JavaScript
The standard drop-down box is very commonly used in HTML. There is often a need to get the text or value of the drop-down box when it changes.
Friends who are new to JS often mistake its value and text and confuse the two.
Sometimes it’s a mistake, because often our value is our text, but in fact they are different things.
Let’s give an example below.
We first create a drop-down box, as follows:
[html]
The JS code is as follows:
[javascript] function GetSelValue() {
var objSel = document.getElementById("selOp");
//This is to get the text
alert ("Current text: " + objSel.options(objSel.selectedIndex).text);
}
function GetSelValue() {
var objSel = document.getElementById("selOp");
("Current value: " + objSel.value);
" "