Reputation: 312
Im using the jQuery validate plugin to validate a form, im wanting to add a class "next" to the submit button if the form is valid only
Send
This is the code i have at the moment all working and validating, just need a function to add the class if valid: http://jsfiddle.net/kKSjL/
Link to jQuery validation page: http://docs.jquery.com/Plugins/Validation/
Upvotes: 0
Views: 3767
Reputation: 21226
Archer has it generally, you just need to specify that as a submitHandler
within the validate call:
$("#commentForm").validate({
submitHandler:function(form){
if (this.valid()){
$('#submit').addClass('next');
form.submit();
}
}
});
Here it is in action: http://jsfiddle.net/ryleyb/kKSjL/1/
Upvotes: 1
Reputation: 26163
However you're triggering the validation check, you need this code...
if ($("#commentForm").valid()) {
$("#submit").addClass("next");
} else {
$("#submit").removeClass("next");
}
Upvotes: 0