Home >Backend Development >PHP Tutorial > 复选框值,该如何处理

复选框值,该如何处理

WBOY
WBOYOriginal
2016-06-13 12:46:17737browse

复选框值

三个值是从数据库读出来,不让他为空就Ok
代码:


应用类型:

 $arr_app_type =explode(";",$rs["app_types"]); 
 $sql = "select * from app_type where id in (10,4,6) order by id";
 $mysql->query($sql);
 while($row = $mysql->fetch_array()){
?>

 />
 

}
?>


------解决方案--------------------
不知道你想问什么
------解决方案--------------------
在form 的onsubmit 事件中调用js函数验证就是了
------解决方案--------------------
参考一下
<script><br />
function foo(){<br />
    var chs=document.getElementsByName('app_types[]');<br />
	var counter=0;<br />
	for(var i=0;i<chs.length;i++){<br />
	     if(chs[i].checked) counter++;<br />
	}<br />
	if(counter==0) return false;<br />
	return true;<br />
}<br />
</script><br />
<form action="" method="post" onsubmit="return foo()"><br />
<input  id="app" name="app_types[]" type="checkbox" value="1"><br />
<input  id="app" name="app_types[]" type="checkbox" value="2"><br />
<input  id="app" name="app_types[]" type="checkbox" value="3"><br />
<input type='submit'><br />
</form>
Statement:
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
Previous article: php中兑现搜索框 Next article: 异常求解 大神们