Getting the text from a drop-down box

后端 未结 12 2339
无人及你
无人及你 2020-11-30 02:23

This gets the value of whatever is selected in my dropdown menu.

document.getElementById(\'newSkill\').value

I cannot however find out what

12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 02:47

    Based on your example HTML code, here's one way to get the displayed text of the currently selected option:

    var skillsSelect = document.getElementById("newSkill");
    var selectedText = skillsSelect.options[skillsSelect.selectedIndex].text;
    

提交回复
热议问题