hi
there are 10 checkboxs and one button in page and users should select one of checkbox
I want if users don't select one of checkboxs when they click button it show error that "you should select one checkbox"
How I can do it?
Best regards
neda
You can try below code:
<asp:checkboxlist id="CheckBoxList1" runat="server"> <asp:ListItem>a</asp:ListItem> <asp:ListItem>b</asp:ListItem> <asp:ListItem>c</asp:ListItem> </asp:checkboxlist> <asp:button id="Button1" runat="server" text="Button" onclientclick="return ValidateCheckBoxList()" /> <script> function ValidateCheckBoxList() { var listItems = document.getElementById("CheckBoxList1").getElementsByTagName("input"); var itemcount = listItems.length; var iCount = 0; var isItemSelected = false; for (iCount = 0; iCount < itemcount; iCount++) { if (listItems[iCount].checked) { isItemSelected = true; break; } } if (!isItemSelected) { alert("Please select an Item."); } else { return true; } return false; } </script>
Hope it helps you.
© COPYRIGHT 2024 ASPSnippets.com ALL RIGHTS RESERVED.