ChrisP
ChrisP

Reputation: 10116

How to use jQuery validate plugin to validate and not submit a form?

I have a set of elements on a page that where I would like to validate user input. However, the data in these elements is not to be submitted (no postback). Can I do this w/ the jQuery validate plugin? Do the elements have to be in a element anyway?

Thanks

Upvotes: 1

Views: 580

Answers (2)

EdanB
EdanB

Reputation: 1496

$(selector).validate({submitHandler:function(form) {//do nothing} ...);

Upvotes: 0

pjnovas
pjnovas

Reputation: 1126

Checkout your submit button, I mean if it is going to the server side (doing a postback) it's because you have an input type='submit', try changing that button to NOT submit. jQuery works on client-side so it is not running a submit itself, I think you are doing it with the button.

For example:

<input type="submit" onclick="return ValidateForm();">

or

<asp:Button id="btn" runat="server" onClientClick="return ValidateForm();"/>

javascript:

function ValidateForm()
{
    var isValid = false;
    isValid = //Your jquery validation
    return isValid;
}

Upvotes: 1

Related Questions