?
Solved

jquery form validate

Posted on 2012-04-03
4
Medium Priority
?
332 Views
Last Modified: 2012-04-08
Hello Experts,

I am using jquery validate, code below.
what happens is when i click the submit button both error messages appears.
and when i click the submit button again then the error messages duplicate and duplicate...

How is it possible to echo one error message at a time meaning deal with each error at the time? And how is it possible to prevent it from infinite duplicates?

$('#form-contact').validate({
	rules: {
		name: {required:true},
		email: {required:true, email:true}				
	},		
	messages: {
	      name: "Please fill in your full name",
              email: "Please provide a valid email address"	
	},
	errorPlacement: function(error, element) {
	   error.appendTo("#error-placement");	
	}
	});
	});

Open in new window

0
Comment
Question by:Refael
[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
4 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37804676
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 37806081
If you can't get it fixed then go back to using the good old javascript method and check for empty values then throw an alert or show the error to the user. Works every time.
0
 
LVL 29

Accepted Solution

by:
sammySeltzer earned 2000 total points
ID: 37807762
If it was me, I would just use this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script type="text/javascript" src="jquery.validate.js"></script>
<style type="text/css">
* { font-family: Verdana; font-size: 96%; }
label { width: 10em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
</style>
  <script>
  $(document).ready(function(){
    $("#commentForm").validate();
  });
  </script>

</head>
<body>


 <form class="cmxform" id="commentForm" method="get" action="">
 <fieldset>
   <legend>Email/Name validation</legend>
   <p>
     <label for="fullname">Name</label>
     <em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" />
   </p>
   <p>
     <label for="cemail">E-Mail</label>
     <em>*</em><input id="cemail" name="email" size="25"  class="required email" />
   </p>
   <p>
     <input class="submit" type="submit" value="Submit"/>
   </p>
 </fieldset>
 </form>
</body>
</html>

Open in new window


Then grab the js code from here:

http://jzaefferer.github.com/jquery-validation/jquery.validate.js
0
 

Author Closing Comment

by:Refael
ID: 37821865
Thank you!
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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

718 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