How do I get selected name from a SELECT (drop downlist) with JavaScript?
I use code similar to the below to get the selected value of a drop down list. Can someone tell me how I would get the selected name from the control also? Thank you.
function myFunction(){
var elem = document.getElementById('selBoxOK');
var selValue = elem.options[ elem.selectedIndex ].value;
}
JavaScriptHTMLWeb Development
Last Comment
Russ Suter
8/22/2022 - Mon
Alexandre Simões
var elem = document.getElementById('selBoxOK');var selName = elem.name;
Open in new window
Options don't have a name, so what you want is the name of the select itself.Also be aware that to get the selected value you can simply call:
Open in new window