Solved

jquery form validate

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now