0
<tr>
<td height="12" align="left" class="cont">
<asp:CheckBox ID="chkacsoutreach" runat="server" />Acs Outreach </td>
</tr>
<tr>
<td height="12" align="left" class="cont">
<asp:CheckBox ID="chkaceportal" runat="server" /> Ace Portal </td>
</tr>

I took some checkboxes in the following way.I should get a message if atleast 1 checkbox is not checked and the values should not be entered into the database.This is the validation i needed.I have written the javascript code as below:but instead of 'controls[]' there should be a groupname which combines all the checkboxes.Iam not understanding what name to give here.Can any one please help me out

<script type="text/javascript" language="javascript">
function validate() { var chks = document.getElementsByName('controls[]'); var hasChecked = false; for (var i = 0; i < chks.length; i++) { if (chks[i].checked) { hasChecked = true; break; } } if (hasChecked == false) { alert("Please select at least one."); return false; } return true; } </script>

Edited by __avd: Keep It Clear - http://www.daniweb.com/forums/faq.php?faq=daniweb_policies

3
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by srujanac#
0

ASP.NET has a validation control that you can attach to the check boxes. What you need to use is the custom validation checkbox. I know that several of the validation controls generate client side and server side validation. I am not sure if the custom validation can does that. In any case, the server side validation will always be present.

The validation controls keep general validation off of the server until it passes the client validation. They also protect your application because if some tries to send invalid data, bypassing your form, the server side validation will be performed and the request rejected.

0
<script type="text/javascript" language="javascript">
                      function checkCheckBoxes() {
//Finding the controls (here chkabi,chkairmanifest)in javascript.

                          var chkabi = document.getElementById('<%=chkabi.ClientID %>');
                          var chkairmanifest = document.getElementById('<%=chkairmanifest.ClientID %>');
//checking whether the check box is checked or not.

if (chkabi.checked == false &&
                    chkairmanifest.checked == false )
{
                              alert('Select any check box!');
                              return false;
                          }
                          else { return true; }
                      }
                    </script>

You can try like this.

Edited by __avd: Added [code] tags. Do wrap your programming code blocks within [code] ... [/code] tags

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.