首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

多组CHECKBOX被选中判断FORM?解决办法

2013-02-24 
多组CHECKBOX被选中判断FORM?不要用JQUERY用JS怎么写一个我先前发的贴子没写明白,从新发个贴。提交框里的内

多组CHECKBOX被选中判断FORM?
不要用JQUERY
用JS怎么写一个
我先前发的贴子没写明白,
从新发个贴。
提交框里的内容都被添写和
name="cate[]" 最少被选中一个
name="area[]" 最少被选中一个


谢谢。




<script>
function check_value(){          



</script>   




<form name="member_join_form" action="mem_join_04.php" method="post" enctype="multipart/form-data" onsubmit="return check_value();">   
<input name="username" type="text" >
<input name="password" type="text" >
<input name="addr" type="text" >
<input name="tel" type="text" >
<label><input type="checkbox" name="cate[]" value="6">aa</label>                                               
<label><input type="checkbox" name="cate[]" value="7">bb</label>                                               
<label><input type="checkbox" name="cate[]" value="8">cc</label><br>                                               <label><input type="checkbox" name="cate[]" value="2">dd</label><br>                                               
<label><input type="checkbox" name="cate[]" 
value="9">ee</label>  


<label><input type="checkbox" name="area[]" 
value="a">11</label>  
<label><input type="checkbox" name="area[]" 
value="b">22</label>  
<label><input type="checkbox" name="area[]" 
value="c">33</label>  

 </form>   



[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function check_value(){          
 var _input = document.getElementsByTagName('input'); 
        var  checkedCount1=0,checkedCount2=0;      
        for(var i=0;i<_input.length;i++){
            if(_input[i].type=='checkbox'&&_input[i].checked){
                if(_input[i].name=='cate[]'){


                    ++checkedCount1;
                }else if(_input[i].name=='area[]'){
                    ++checkedCount2;
                }
            } else if(_input[i].type=='text'&&_input[i].value==''){
                return false;
            }
        }
        if(checkedCount2>0&&checkedCount1>0){
            return true;
        }
        return false;
}
</script>
</head>

<body>
<form name="member_join_form" action="mem_join_04.php" method="post" enctype="multipart/form-data" onsubmit="return check_value();">   
<input name="username" type="text" >
<input name="password" type="text" >
<input name="addr" type="text" >
<input name="tel" type="text" >
<label><input type="checkbox" name="cate[]" value="6">aa</label>                                               
<label><input type="checkbox" name="cate[]" value="7">bb</label>                                               
<label><input type="checkbox" name="cate[]" value="8">cc</label><br>                                               <label><input type="checkbox" name="cate[]" value="2">dd</label><br>                                               
<label><input type="checkbox" name="cate[]" 
value="9">ee</label>  
 
 
<label><input type="checkbox" name="area[]" 
value="a">11</label>  
<label><input type="checkbox" name="area[]" 
value="b">22</label>  
<label><input type="checkbox" name="area[]" 
value="c">33</label>  
 <input type="submit" />
 </form> 
</html>
这样试试

热点排行
Bad Request.