Reputation: 13763
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>
Upvotes: 0
Views: 87
Reputation: 20371
If this is the plugin you're using, you could use the onValid
and onInvalid
callback functions of the plugin and hook in the desired behaviour there.
For example, remove the JS from your HTML:
<button id="btnSave" name="btnSave" runat="server" type="submit" style="font-size:11px;font-family:Verdana;font-weight:bold;" >Save</button>
and change the call to the plugin to something like
$("#btnSave").validate({onValid:addUser});
If you're using some other validation plugin, check the documentation - any good plugin will provide similar hooks that you can use.
Upvotes: 1