PHP中获取CHECKBOX提交的内容及checkbox全选
<script type= "text/javascript" >?
|
function check_all(obj,cName)?
|
???? var checkboxs = document.getElementsByName(cName);?
|
???? for ( var i=0;i<checkboxs.length;i++){checkboxs[i].checked = obj.checked;}?
|
<form id= "form1" name= "form1" method= "post" action= "receive.php" >?
|
<table width= "100%" ><tr>?
|
<p><input type= "checkbox" name= "all" onclick= "check_all(this,'checkbox[]')" />全选/全不选</p>?
|
??????????? <input type= "checkbox" name= "checkbox[]" value= "item1" />?
|
??????????? <input type= "checkbox" name= "checkbox[]" value= "item2" />?
|
??????????? <input type= "checkbox" name= "checkbox[]" value= "item3" />?
|
??????????? <input type= "submit" name= "Submit" value= "提交" />?
|
如果名字不用数组的话,php只能获取到最后一个checkbox的值? |
$checkbox = $_POST [ 'checkbox' ];?
|
for ( $i =0; $i <= count ( $checkbox ); $i ++)?
|
if (! is_null ( $checkbox [ $i ]))?
|
{ $chechvalue = $checkbox [ $i ]; break ;}?
|
for ( $i =0; $i <= count ( $checkbox ); $i ++)?
|
if (! is_null ( $checkbox [ $i ]))?
|
{ $chechvalue .= $checkbox [ $i ]}?
|
?
?
转自:http://www.cnblogs.com/freespider/archive/2011/03/18/1988308.html