日期:2014-05-17  浏览次数:20398 次

复选框值

三个值是从数据库读出来,不让他为空就Ok
代码:
<tr>
<td class="add_table_left">应用类型:</td>
<td class="add_table_right2">
<?php
 $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()){
?>
<input  id="app" name="app_types[]" type="checkbox" value="<?php echo $row["id"];?>" 
<?php if(in_array($row["id"],$arr_app_type)) echo "checked";?> />
<?php echo $row["name"];?>&nbsp;

<?php
}
?>
</td>
</tr>

------解决方案--------------------
不知道你想问什么
------解决方案--------------------
在form 的onsubmit 事件中调用js函数验证就是了
------解决方案--------------------
参考一下
<script>
function foo(){
    var chs=document.getElementsByName('app_types[]');
var counter=0;
for(var i=0;i<chs.length;i++){
     if(chs[i].checked) counter++;
}
if(counter==0) return false;
return true;
}
</script>
<form action="" method="post" onsubmit="return foo()">
<input  id="app" name="app_types[]" type="checkbox" value="1">
<input  id="app" name="app_types[]" type="checkbox" value="2">
<input  id="app" name="app_types[]" type="checkbox" value="3">
<input type='submit'>
</form>