How can I get a list of all values in select box?

前端 未结 4 2103
花落未央
花落未央 2021-02-05 02:10

I am stumped. I have a form with a dropdown list, and I would like to grab a list of all the values in the list. I pulled the below example from w3 schools (yes, I know it\'s un

4条回答
  •  没有蜡笔的小新
    2021-02-05 02:43

    Change:

    x.length
    

    to:

    x.options.length
    

    Link to fiddle

    And I agree with Abraham - you might want to use text instead of value

    Update
    The reason your fiddle didn't work was because you chose the option: "onLoad" instead of: "No wrap - in "

提交回复
热议问题