dsf487787 2017-08-02 07:08 采纳率: 100%
浏览 29
已采纳

在不选择值的情况下自动获取多个选择和显示的所有值

How can I get all value of the multiple-select and display into the other page. I try to follow different answer from different stackoverflow questions that are related with my question but still they are almost the same giving me wrong output. But correct me if I wrong with that.

I try to analyze and implement answer in the following link that has not display value.
1. Getting All $_POST From Multiple Select Value
2. How to get multiple selected values of select box in php?
3. How to get multiple selected values of select box in php?
4. Get all variables sent with POST?
5. Using $_POST to get select option value from HTML

How can I get the value from my select when I try to submit it using POST or GET? The following codes I am using.

HTML

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
  <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <!-- Bootstrap CSS File  -->
  <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
  <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
  />
</head>
<body>
  <form id="form1" name="form1" method="GET" action="display.php">
    <div class="row">     
      <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
        <select name="test" id="sbTwo" multiple="multiple" class="form-control">
          <option value="Alpha">Alpha</option>
          <option value="Beta">Beta</option>
          <option value="Gamma">Gamma</option>
          <option value="Delta">Delta</option>
          <option value="Epsilon">Epsilon</option>
        </select>
      </div>
    </div>    
    <br />
    <input type="submit" class="btn btn-default" name="submit" value="Submit" tabindex="2" />
  </form>
</body>
</html>

<style type="text/css">
  /* Button Primary */
  .btn-primary {
    color: #0275d8;
    background-image: none;
    background-color: transparent;
    border-color: #0275d8;
  }

  .btn-primary:hover {
    background-color: #0275d8;
    color: white;
    border-color: #0275d8;
  }
</style>

PHP

<?php
if (isset($_GET['test'])) {
 foreach ($_GET['test'] as $value){  
    echo $value."
";
   }
}else{
    echo 'ERROR';
}
?>
  • 写回答

2条回答 默认 最新

  • douwa6220 2017-08-02 07:13
    关注

    change the name to test[] for multi select

     <select name="test[]" id="sbTwo" multiple="multiple" class="form-control">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器