<form name="form1" id="form1" method="post" action="myphp.php" onSubmit="return Checker()">
<input type="checkbox" name="item" value="1">1<br>
<input type="checkbox" name="item" value="2">2<br>
<input type="checkbox" name="item" value="3">3<br>
<input type="checkbox" name="item" value="4">4<br>
<input type="hidden" name="items" value="">
<input type="submit" value="Submit">
</form>
<script language="javascript">
<!--
function Checker()
{
form1.items.value = "";
if ( !form1.item.length ) // 只有一个复选框,form1.item.length = undefined
{
if ( form1.items.checked )
form1.items.value = form1.item.value;
}
else
{
for ( i = 0 ; i < form1.item.length ; i++ )
{
if ( form1.item(i).checked ) // 复选框中有选中的框
{
form1.items.value = form1.item(i).value;
for ( j = i + 1 ; j < form1.item.length ; j++ )
{
if ( form1.item(j).checked )
{
form1.items.value += " "; //用空格做分割符
form1.items.value += form1.item(j).value;
}
}
break;
}
}
}
return true;
}
-->
</script>
$items = explode(" ", $HTTP_POST_VARS["items"]);