For example, jscheckbox limits the number of checkboxes to six.

Source: Internet
Author: User

For example, jscheckbox limits the number of checkboxes to six.

Today, when I was working on a project, I encountered a problem. I need to display multiple checkbox check boxes, but I can only select up to six. After debugging for a long time, I finally came out. The Code is as follows:

<SCRIPT LANGUAGE="JavaScript"> var c=0,limit=6; function doCheck(obj) { obj.checked?c++:c--; if(c>limit){ obj.checked=false; alert("over"); c--; } } </SCRIPT> 

The result is as follows:


Js question: How can I limit the number of checkboxes that cannot be submitted?

Function selAll (){
Var delmessage = document. getElementsByName ("delimiter ");
Var len = delmessage. length;
For (var I = 0; I <len; I ++ ){
If (len <7 ){

} Else {}
}

How does JS control the check box selection times?

You can add a counter.
<Script>
Var s = 0;
Function checkbox_max (obj, num ){
If (s> = nmu)
{
Alert ("your selections have exceeded! ");
// Operations that exceed the selected number of times
}
Else
{
S ++;
// What should I do if it is not too old?
}
}
</Script>

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.