<?php
if(!$_REQUEST['cbox']) {
?>
<script language="Javascript">
<!--
alert('你没有进行选择');
//-->
</script>
<?}
else {
foreach($_REQUEST['cbox'] as $key=>$val) {
print "你选择的值为:".$val."<br>";
}
}?>
<body>
<form name='form1' method="POST" action="4444.php">
<input type="checkbox" name="cbox[]" value="a">Checkbox1</p>
<input type="checkbox" name="cbox[]" value="b">Checkbox2</p>
<input type="checkbox" name="cbox[]" value="c">Checkbox3</p>
<p><input type="submit" value="提交" name="B1">
<input type="reset" value="重置" name="B2"></p>
</form>
</body>
if(!$_REQUEST['cbox']) {
?>
<script language="Javascript">
<!--
alert('你没有进行选择');
//-->
</script>
<?}
else {
foreach($_REQUEST['cbox'] as $key=>$val) {
print "你选择的值为:".$val."<br>";
}
}?>
<body>
<form name='form1' method="POST" action="4444.php">
<input type="checkbox" name="cbox[]" value="a">Checkbox1</p>
<input type="checkbox" name="cbox[]" value="b">Checkbox2</p>
<input type="checkbox" name="cbox[]" value="c">Checkbox3</p>
<p><input type="submit" value="提交" name="B1">
<input type="reset" value="重置" name="B2"></p>
</form>
</body>
<script language=javascript>
function ckck()
{
if(document.form1.cbox[].value.length==0)
{
alert("请选择");
document.form1.cbox[].focus();
return false;
}
return true;
}
</script>
<form name=form1 onsubmit="return ckck();" ...>
....
----
呵呵:-)
function check(ele){
for(var i=0;i<ele.elements.length;i++){
if (ele.elements[i].name.substring(0,4) != 'cbox') {
continue;
}
if (ele.elements[i].checked == true)
return true;
}
alert("请选择一个选项");
return false;
}
</script>
<body>
<form method="POST" action="test2.php" onSubmit="return check(this);">
<input type="checkbox" name="cbox[]" value="a">Checkbox1</p>
<input type="checkbox" name="cbox[]" value="b">Checkbox2</p>
<input type="checkbox" name="cbox[]" value="c">Checkbox3</p>
<p><input type="submit" value="提交" name="B1"> <input type="reset" value="重置" name="B2"></p>
</form>
</body>我试了一下,应该是可以的.
for ( i = 0; i < 3; i ++ ) {
cbox = "cbox["+i+"]";
if( document.thisform.elements[cbox].checked == true)
{
var a = true;
}
}
if ( !a ){
alert("您没有选择!");
return false;
}
}
//-->
</SCRIPT>
<form method="POST" action="" name="thisform">
<input type="checkbox" name="cbox[0]" value="a">Checkbox1</p>
<input type="checkbox" name="cbox[1]" value="b">Checkbox2</p>
<input type="checkbox" name="cbox[2]" value="c">Checkbox3</p>
<p><input type="submit" value="提交" name="B1" onclick="return CheckSubmit()"> <input type="reset" value="重置" name="B2"></p>
</form>