?
Solved

jQuery Multiple forms validation

Posted on 2012-03-23
2
Medium Priority
?
386 Views
Last Modified: 2012-04-10
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?
0
Comment
Question by:slightlyoff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 37760214
$(".selector").validate({
   submitHandler: function(form) {
     alert(form.attr("id"));
     $(form).ajaxSubmit(); // not sure about the $() here since I think that is any form on the page
   }
})

http://docs.jquery.com/Plugins/Validation/validate
0
 
LVL 1

Author Comment

by:slightlyoff
ID: 37828215
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question