JS limit checkbox Check number and PHP to get multiple Checkbbox method in-depth analysis

Source: Internet
Author: User
Tags php file
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/> ";


}


}


?>
Related Article

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.