提交页
<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;}
}
</script>
<form id=
"form1"
name=
"form1"
method=
"post"
action=
"receive.php"
>
<table width=
"100%"
><tr>
<td></td>
<td colspan=
"2"
>
<div align=
"center"
>
<p><input type=
"checkbox"
name=
"all"
onclick=
"check_all(this,'checkbox[]')"
/>全选/全不选</p>
<input type=
"checkbox"
name=
"checkbox[]"
value=
"item1"
/>
1
<input type=
"checkbox"
name=
"checkbox[]"
value=
"item2"
/>
2
<input type=
"checkbox"
name=
"checkbox[]"
value=
"item3"
/>
3
</div>
</td>
<td></td></tr>
<tr><td></td>
<td colspan=
"2"
>
<div align=
"center"
>
<input type=
"submit"
name=
"Submit"
value=
"提交"
/>
</div>
</td>
<td></td></tr>
</table>
如果名字不用数组的话,php只能获取到最后一个checkbox的值
receive.php
$checkbox
=
$_POST
[
'checkbox'
];
for
(
$i
=0;
$i
<=
count
(
$checkbox
);
$i
++)
{
if
(!
is_null
(
$checkbox
[
$i
]))
{
$chechvalue
=
$checkbox
[
$i
];
break
;}
}
echo
$chechvalue
;
for
(
$i
=0;
$i
<=
count
(
$checkbox
);
$i
++)
{
if
(!
is_null
(
$checkbox
[
$i
]))
{
$chechvalue
.=
$checkbox
[
$i
]}
}
echo
$chechvalue
;
没有评论:
发表评论