How to obtain multi-select values ​​in php select

WBOY
Release: 2016-07-25 09:00:29
Original
1537 people have browsed it
为大家举一个php获取select多选值的例子,有需要的朋友,可以参考下。

完整代码如下:

<form action="?act=s" name=f method="post">
 <select size="5" name="posTypeSelect[]" multiple="multiple" id="posTypeSelect" style="width:240px">
<option value=1>项目1</option>
<option value=2>项目2</option>
<option value=3>项目3</option>
</select>
<input type="submit" id="su" value="开始搜索" onClick="return CheckInput()" >
</form>
 <script language="javascript">
 <!--
  function SelectAll(Objname) {
  ObjID    = document.getElementById(Objname);
  if (ObjID != -1) {
   for (i=0; i<ObjID.length; i++)
   
   ObjID.options[i].selected = true;
  }
 }
 
 function CheckInput() {
 
  SelectAll("posTypeSelect");
 }
 
 // -->
 </SCRIPT>
Copy after login

说明: onClick="return CheckInput()" //所有全选所有项目。

关键内容: name="posTypeSelect[]" id="posTypeSelect" 获取值的循环过程:

$ap="";
  $temp_x=$_POST[posTypeSelect];
  for($i=0;$i<count($temp_x);$i++){ 
  $ap=$ap.$temp_x[$i].","; 
  }
  $z=substr($ap,0,-1);//去除末尾单引号职位分类
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!