Home > DeveloperSection > Forums > how to Check any 2 checkBox from 4 CheckBoxes?
jayprakash sharma
jayprakash sharma

Total Post:117

Posted on    September-05-2014 12:17 AM

 ASP.Net ASP.Net 

 1 Reply(s)
 1317  View(s)
Rate this:

I want the user can check only 2 checkbox,exceeding that alert box should pop up.


        <form id="form1" runat="server">


            <table width="100%">



                    <asp:CheckBox id="q3a" runat="server" Text="Public" />



                    <asp:CheckBox id="q3b" runat="server" Text="void" />



                    <asp:CheckBox id="q3c" runat="server" Text="protected"/>



                    <asp:CheckBox id="q3d" runat="server" Text="return" />




            <asp:Button ID="btnSubmit" Text="submit" runat="server"/>




how can i write javascript for this, i have tried but can't find any way out.

Sumit Kesarwani

Total Post:378

Posted on    September-05-2014 12:33 AM

Hi Jay, 

try this:

$("input[type='checkbox']").change(function () {

        var n = $("input:checkbox:checked").length;

        if (n > 2) {

            alert('2 are already selected!');

            $(this).attr("checked", false);



Don't want to miss updates? Please click the below button!

Follow MindStick