JS limit checkbox Check number and PHP to get multiple Checkbbox method to deeply analyze _php skills

Source: Internet
Author: User
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/> ";
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.