Valdating Check boxes

M

Mark Rae [MVP]

Can anyone point me to an example?

<script type="text/javascript">
function validateForm()
{
if (!document.getElementById('<%=MyCheckBox.ClientID%>').checked)
{
alert ('You must agree to the terms');
document.getElementById('<%=MyCheckBox.ClientID%>').focus();
return false;
}
}
</script>

<form id="form1" runat="server">
<asp:CheckBox ID="MyCheckBox" runat="server" />
<asp:Button ID="MyButton" Text="Submit" OnClick="MyButton_Click"
OnClientClick="return validateForm();" />
</form>
 
B

bruce barker

pretty trival:

<script type="text/javascript">
function ackCheck(s,a)
{
a.IsValid = document.getElementById('<%=chkAck.ClientID%>').checked;
return a.IsValid;
}
</script>

<asp:CustomValidator runat=server
ControlToValidate="chkAck"
ErrorMessage="Please Acknowledge"
ClientValidationFunction="ackCheck"
Display="Dynamic"
/>
<asp:checkbox runat=server id="chkAck"
Text="Acknowledge" />


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top