How do I get selected name from a SELECT (drop downlist) with JavaScript?

earwig75
earwig75 used Ask the Experts™
on
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;
         }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Alexandre SimõesManager / Solutions Architect

Commented:
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:
var elem = document.getElementById('selBoxOK');
var selName = elem.value;

Open in new window

Senior Software Developer
Commented:
Just change .value to .innerText. That should give you the desired result.
Russ SuterSenior Software Developer

Commented:
Just change .value to .innerText. That should give you the desired result.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial