4

I have a form, on which I have a button - When the user clicks the button Add, a function is called which adds a new row to a table in the same form, but using javascript.

I have used the jquery validation plugin,the problem I have is that the validation only fires when I use a submit button,but not when my button is clicked, which runs my function.

I understand why this is - The validation plugin wants the form to be submitted.

Is there any way I can cause the validation to run and return its result? My function can then either do nothing if the validation fails, or go ahead and post the user entered data to my function if the validation passes. Obviously I would need to do this without the form actually submitting.

Any help greatly appreciated - I've tried a few ideas I found whilst Googling on this, but nothing has worked so far.

Thank you beforehand.

1 Answer 1

2

If you mean http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/

if ($j('#Form1').validationEngine({ returnIsValid: true })) {
  //is valid
}

Or if you mean: http://docs.jquery.com/Plugins/Validation

$("#myform").validate({
 submitHandler: function(form) {
   // some other code
   return false;
 }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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