-1

I am using jQuery form validation plugin. My problem is that I want to use it to check if all fields are valid and then run my custom javascript.

Please see the below example:

if(valid){
    //enable save button
    //if user accept terms(by using check the check box)
} else {
    return false;
}
Sparky
  • 98,165
  • 25
  • 199
  • 285
Sohail Qureshi
  • 689
  • 11
  • 24

1 Answers1

1

Assuming your form has the ID my-form-id, you would first call:

$("#my-form-id").validate();

This validates the form. And then you can do:

if($("#my-form-id").valid()){
    //enable save button
    //if user accept terms(by using check the check box)
} else {
    return false;
}

See full doc here: http://jqueryvalidation.org/valid

ced-b
  • 3,957
  • 1
  • 27
  • 39
  • The `.validate()` method does **not** _"validate the form"_. The `.validate()` method ***initializes*** the plugin on your form. Validation is then triggered *automatically* by certain events captured by the plugin. – Sparky Jan 04 '15 at 18:26