Hello:
The code below is working fine, but when I incorporate the JavaScript function (checkAgreement) below into my existing pages with alot more code it makes certain code on my page not working.
I need to make the end user checks on the checkbox before moving to the next screen.
Is there another way to validate the checkbox like below that I can use? Thanks in advance.
The code below is working fine, but when I incorporate the JavaScript function (checkAgreement) below into my existing pages with alot more code it makes certain code on my page not working.
I need to make the end user checks on the checkbox before moving to the next screen.
Is there another way to validate the checkbox like below that I can use? Thanks in advance.
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="validateCheckBox2.aspx.cs" Inherits="validateCheckBox2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function checkAgreement(source, args)
{
var elem = document.getElementById('<%= chkAgree.ClientID %>');
if (elem.checked)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="chkAgree" runat="server" />
<asp:Label ID="Label1" AssociatedControlID="chkAgree" runat="server">I agree to the term</asp:Label>
<br />
<asp:CustomValidator ID="chkAgreeValidator" runat="server" ClientValidationFunction="checkAgreement" ErrorMessage="You must agree to the terms and conditions."></asp:CustomValidator>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Enroll in this Course!" />
</div>
</form>
</body>
</html>