I am trying to validate using jquery validation and the error messages displayed it in a div container. My problem is when i typed something to my input fields error message always appear in “div.info” but i just want error messages always appear when i submit a form. And my next problem is when i submit more than once error messages also display more than once too?
My code is like below
Html code
<div class="info"></div>
<form id="fmlogin">
<fieldset>
<label>Email Address</label>
<input type="text" name="email" />
<label>Password</label>
<input type="password" name="password"/>
<input type="submit" value="login" />
</fieldset>
</form>
jquery
<script type="text/javascript">
$(document).ready(function(){
$("form#fmlogin").submit(function() {
data= $("form#fmlogin").serialize();
return false;
});
$("#fmlogin").validate({
rules: {
email: {
required: true,
email:true
},
password: {
required: true,
}
},
messages: {
email: {
required: "Email Address is required",
email:"Email Address is not Valid"
},
password: {
required: "Password is required",
}
},
errorElement: "div",
wrapper: "div",
errorPlacement: function(error, element) {
error.appendTo($('.info'));
},
submitHandler: function(form){
$.ajax({
type: "POST",
url: "login.php",
data:data,
success: function(response){
$(".info").text(response);
}
});
}
});
});
</script>
I am new with jquery validation, please help?
Thanks
fmlogin
use this