---
title: "how to Check any 2 checkBox from 4 CheckBoxes?"  
description: "how to Check any 2 checkBox from 4 CheckBoxes?"  
author: "Anonymous User"  
published: 2014-09-05  
updated: 2014-09-05  
canonical: https://www.mindstick.com/forum/2250/how-to-check-any-2-checkbox-from-4-checkboxes  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# how to Check any 2 checkBox from 4 CheckBoxes?

I want the [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) can [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) only 2 [checkbox](https://www.mindstick.com/articles/291/how-should-use-checkbox-control-in-vb-dot-net),exceeding that [alert box](https://www.mindstick.com/forum/117/problem-in-displaying-alert-box-in-asp-dot-net) should [pop up](https://answers.mindstick.com/qa/50233/what-to-do-with-the-issues-that-may-pop-up-at-the-time-of-usb-device-installation).

```
 <body>        <form id="form1" runat="server">        <div>            <table width="100%">                <tr>                    <td>                    <asp:CheckBox id="q3a" runat="server" Text="Public" />                    </td>                    <td>                    <asp:CheckBox id="q3b" runat="server" Text="void" />                    </td>                    <td>                    <asp:CheckBox id="q3c" runat="server" Text="protected"/>                    </td>                    <td>                    <asp:CheckBox id="q3d" runat="server" Text="return" />                    </td>                </tr>            </table>            <asp:Button ID="btnSubmit" Text="submit" runat="server"/>        </div>        </form>    </body>
```

how can i write [javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) for this, i have tried but can't find any way out.

## Replies

### Reply by Sumit Kesarwani

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);        }    });
```


---

Original Source: https://www.mindstick.com/forum/2250/how-to-check-any-2-checkbox-from-4-checkboxes

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
