I am using JQuery validate and calling a javascript method on the onclick event. But even when the validation fails, it still calls this method. How do I check within the method if the validation failed, so that I can prevent this code from running?
<button id="btnSave" name="btnSave" runat="server" type="submit" onclick="addUser()" style="font-size:11px;font-family:Verdana;font-weight:bold;" >Save</button>
If this is the plugin you’re using, you could use the
onValidandonInvalidcallback functions of the plugin and hook in the desired behaviour there.For example, remove the JS from your HTML:
and change the call to the plugin to something like
If you’re using some other validation plugin, check the documentation – any good plugin will provide similar hooks that you can use.