I have a required field validator that is functioning correctly when it's on its own and stops the post back. However, when I add JavaScript to enable the "next" button upon checking a checkbox, the required field validator will trigger when clicking "next" with an empty txtEmail field, but it won't prevent the post from executing. How can I make this work?
<ul>
<li>FirstName<asp:textbox ID="txtFirstName" runat="server"></asp:textbox></li>
<li>LastName<asp:textbox ID="txtLastName" runat="server"></asp:textbox></li>
<li>Email<asp:textbox ID="txtEmail" runat="server" ValidationGroup="group"></asp:textbox></li>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="group" runat="server" ErrorMessage="Required!" ControlToValidate="txtEmail"></asp:RequiredFieldValidator>
</ul>
</div>
<div>
<input type="checkbox" id="ckAgree" onclick="EnableSubmit(this)"/>
I agree to the <a data-toggle="modal" data-target="#myModal">terms and conditions</a>
<asp:button ID="btnNext" runat="server" text="Next" Enabled="false" ValidationGroup="group" OnClick="btnNext_Click" />
<asp:Label ID="lblSuccess" runat="server" Text=""></asp:Label><asp:HiddenField ID="hf_ID" runat="server" />
***javascript**:
EnableSubmit = function (val) {
var sbmt = document.getElementById("btnNext");
if (val.checked == true) {
sbmt.disabled = false;
}
else {
sbmt.disabled = true;
}
}