【问题标题】:Multiple select not working while submiting please give me to select multiple option code提交时多选不起作用请让我选择多个选项代码
【发布时间】:2016-11-10 09:44:29
【问题描述】:

<form method='post' action=''>
  <select name='select1' multiple="true">
    <option value='1' <?php if(isset($_POST[ 'select1'])) { if($_POST[ 'select1']=='1' ) { echo 'selected'; } } ?>>imtiyaz</option>
    <option value='2' <?php if(isset($_POST[ 'select1'])) { if($_POST[ 'select1']=='2' ) { echo 'selected'; } } ?>>narendra</option>
    <option value='3' <?php if(isset($_POST[ 'select1'])) { if($_POST[ 'select1']=='3' ) { echo 'selected'; } }?>>shekar</option>
  </select><br><br><br>

  <select name='select2' multiple>
    <option value='1' <?php if(isset($_POST[ 'select2'])) { if($_POST[ 'select2']=='1' ) { echo 'selected'; } } ?>>sumit</option>
    <option value='2' <?php if(isset($_POST[ 'select2'])) { if($_POST[ 'select2']=='2' ) { echo 'selected'; } } ?>>arun</option>
    <option value='3' <?php if(isset($_POST[ 'select2'])) { if($_POST[ 'select2']=='3' ) { echo 'selected'; } } ?>>vinay</option>
  </select><br><br><br>

  <select name='select3' multiple>
    <option value='1' <?php if(isset($_POST[ 'select3'])) { if($_POST[ 'select3']=='1' ) { echo 'selected'; } } ?>>rohth</option>
    <option value='2' <?php if(isset($_POST[ 'select3'])) { if($_POST[ 'select3']=='2' ) { echo 'selected'; } } ?>>pawan</option>
    <option value='3' <?php if(isset($_POST[ 'select3'])) { if($_POST[ 'select3']=='3' ) { echo 'selected'; } } ?>>suresh</option>
  </select>

  <input type='submit' value='submit' name='submit'>
</form>

我的多个选择框在提交表单时不起作用,而且我想在刷新我选择的页面后在选择框中显示值

【问题讨论】:

  • “它不工作”是什么意思?没有足够的信息让任何人帮助你
  • 您可能应该先将元素更改为数组:name='select1[]' 等。
  • 当我提交表单时,我可以在选择中获得多个值
  • 是的,它不工作
  • 寻求调试帮助的问题必须包括所需的行为和特定问题或错误 - “不工作”不是特定问题或错误。请阅读:stackoverflow.com/tour

标签: javascript php jquery html


【解决方案1】:

试试这个:

<select name='select1[]' multiple= "true">

多选下拉列表的名称必须是一个数组,以便它可以接受其中的多个选定值。您可以通过使用 foreach() 迭代数组来使用它,例如:

foreach($_REQUEST['select1'] as $selection)
{
    // your code
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-25
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多