Link to home
Start Free TrialLog in
Avatar of slightlyoff
slightlyoff

asked on

jQuery Multiple forms validation

I'm using a jQuery forms validation code I found online to validate 2 different forms on the same page.  1 form is a registration form, the other is a login form, in case they've already registered.

When the forms are submitted, if they pass validation, they go to this function:

$.validator.setDefaults({
	submitHandler: function() { 
		
			alert("submitted!");	
	}
});

Open in new window


The trick is, I want to run ajax to process the results, so I need to know what form was submitted, but I'm not sure how to do that.

The first form's id is "registerForm"  and the second form's id is "loginForm"

The validation looks like this:
$("#loginForm").validate({
		rules: {
			email: {
				required: true,
				email: true
			}
		},
		messages: {
			email: "Please enter a valid email address"
		}
		
	});

Open in new window


The registration form's validation is similar, with more fields.  

If I submit either form, and they pass the validation, I get the "submitted!" alert.

Any ideas on how I tell which one was submitted?
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of slightlyoff
slightlyoff

ASKER

Thank you for your help!  I had to step away from this project, and forgot to award points.
I appreciate your response, and the link was especially useful.