The first is JS limit checkbbox Check the number of code:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"
"Http://www.w3.org/TR/html4/loose.dtd" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> limit check box number of selections </title>
<script type= "Text/javascript" >
function Checkdate (n) {
var checkedcount=0;
for (Var i=0;i<myform.course.length i + +) {
if (myform.course[i].checked) {
checkedcount++;
}
}
if (checkedcount>n) {
Alert ("Cannot choose more than three courses");
return false;
}
}
</script>
<body>
<form name= "MyForm" method= "post" id= "MyForm" action= "test.php" >
Please choose the course of this semester (up to three):<br>
<input type= "checkbox" Name= "course[]" value= "language" onclick= "return Checkdate (3)" > Chinese <br>
<input type= "checkbox" Name= "course[]" value= "math" onclick= "return Checkdate (3)" > Math <br>
<input type= "checkbox" Name= "course[]" value= "English" onclick= "return Checkdate (3)" > English <br>
<input type= "checkbox" Name= "course[]" value= "chemical" onclick= "return Checkdate (3)" > Chemistry <br>
<input type= "checkbox" Name= "course[]" value= "physical" onclick= "return Checkdate (3)" > Physics <br>
<input type= "checkbox" Name= "course[]" value= "politics" onclick= "return Checkdate (3)" > Politics <br>
<input type= "Submit" value= "submitted" >
<input type= "reset" value= "Cancel" >
</form>
</body>
and then the PHP file to get the Checkbbox method:
Copy Code code as follows:
<?php
$course =$_post[' Course '];
for ($i =0; $i <count ($course); $i + +)
{
if ($course [$i]!= "")
{
echo $course [$i]. " <br/> ";
}
}
?>