Getting an option text/value with JavaScript

后端 未结 4 1889
迷失自我
迷失自我 2020-11-30 07:00

Answer: var option_user_selection = element.options[element.selectedIndex].text

I am trying to build a form that fills in a person\'s o

相关标签:
4条回答
  • 2020-11-30 07:35
    var option_user_selection = document.getElementById("maincourse").options[document.getElementById("maincourse").selectedIndex ].text
    
    0 讨论(0)
  • 2020-11-30 07:58
    form.MySelect.options[form.MySelect.selectedIndex].value
    
    0 讨论(0)
  • 2020-11-30 07:59

    You can use:

    var option_user_selection = element.options[ element.selectedIndex ].text
    
    0 讨论(0)
  • 2020-11-30 08:00

    In jquery you could try this $("#select_id>option:selected").text()

    0 讨论(0)
提交回复
热议问题