Solved

jquery form validate

Posted on 2012-04-03
4
326 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
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 28

Accepted Solution

by:
sammySeltzer earned 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
age from date of birth 4 41
Where is java script information saved? 2 50
add a 3rd selection to sum 7 25
Button to go back 3 24
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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 …
The viewer will learn how to dynamically set the form action using jQuery.
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)

786 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