I’ve written a JavaScript function which validates form input and highlights the input fields and displays any error messages, which I have tested and all works fine.
I have called this function from the OnClientClick attribute of an asp:Button tag. However, if the JavaScript function determines there to be validation errors, I want to stop the form from submitting. How do I do this?
I am a VB.NET newbie, so any help would be appreciated. Thanks.
ASPX
<asp:Button ID="btnSubmit" Text="Save Changes" runat="server" OnClientClick="validateEMI();" />
JavaScript
function validateEMI() {
// a big bunch of validation checks...
if (errorOnForm == true) {
document.getElementById("message").innerHTML = errorMsg;
return;
}
}
return false;
EDIT: and
validateEMIshould be hooked withonsubmitevent