dqvy87517
2013-11-21 15:40
浏览 153
已采纳

如何检索所有<select>标签选项?

I have a form with a drop down list that is being populated by the user using java script. I would like to retrieve (on server side) all options of this drop down list on submit. I mean to all of them, not only the ones that have been selected, since they are not being signed as "selected". Is there a way of doing it by php code? I don't want to use a java script solution.

Thank you

图片转代码服务由CSDN问答提供 功能建议

我有一个带有下拉列表的表单,该表由用户使用java脚本填充。 我想要 检索(在服务器端)提交时此下拉列表的所有选项。 我的意思是他们所有人,不仅是那些被选中的人,因为他们没有被签名为“选中”。 有没有办法通过PHP代码来做? 我不想使用java脚本 解决方案。

谢谢

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • drdyszuy488152 2013-11-21 15:42
    已采纳

    The unselected options in a <select> element are not sent to the server by the web browser, so you have no way to get these with PHP. You will have to use JavaScript.

    You mention that the list is being populated by JavaScript in the first place, perhaps you could modify that JavaScript to also stick the values in a hidden form field up front, so that they are available server-side when the form is submitted.

    Otherwise you would need to create an onsubmit handler to get all the options using Javascript, and then possibly store them in a hidden form field.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongniuxia8650 2013-11-21 15:42

    The browser won't send the unselected options to the server, so: No

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题