3

I am trying to use jquery validator plugin and form submit via ajax in jquery.....

Validator plugin works with <input type="submit" value="Add a client" id="clientadd"/> but my form submit works with <input type="button" value="Add a client" id="clientadd"/>.....

<form id="addform" autocomplete="off">
 //My controls here
</form>

I didn't specify action and method attributes here as i ll submit my form using jquery.ajax().... Any suggestion how to get both working together....

2 Answers 2

2

You could specify a submitHandler that will perform the form submission once validation succeeds:

$('form').validate({
    submitHandler: function(form) {
       // TODO: submit your form in ajax here
    }
});

So if you are using the jQuery.form plugin to ajaxify your form:

$('form').validate({
    submitHandler: function(form) {
        $(form).ajaxSubmit();        
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

@Pandiya, as always glad to help :-)
looked at your profile page and the MVC project structure article was really nice... But NHibernate is really tough for me to get a hold on it...
1

You can add action="" so it will be valid HTML, and use the type="submit" button without problems. Simply catch the submit with jQuery and prevent the normal submit from occuring:

$('#addform').submit(function() {
  // your stuff here to process the form

  // end with
  return false;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.