The following is the JS limit checkbox check number and PHP to obtain multiple Checkbbox method for detailed analysis of the introduction, the need for friends can refer to the next
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" >
<html>
<head>
<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>
</head>
<body>
<form name= "MyForm" method= "post" id= "MyForm" action= "test.php" >
Please select the class (up to three):<br>
this semester
<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=" political "onclick=" return Checkdate (3) "> Politics <br>
<input type= "Submit" value= "submitted" >
<input type= "reset" value= "Cancel" >
</form>
</body>
</html>
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/> ";
}
}
?>