April 7, 2012
Error message not get cleared while clicking the reset button
Question by vivek
I am using jquery.validate.js file to validate an input form, It works fine, my problem is the error messages are not get cleared while clicking the reset button in the form.
how to get clear the form?
here is the code
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
javascript function
$(document).ready(function(){
$("#demo-form").validate({
rules: {
name: "required",
address: "required",
}
HTML Code
<div><input type="text" id="name" name="name" /></div>
<div><input type="text" id="address" name="address" /></div>
<div> <input type="submit" id="submit" value="Validate!" />
<input type="reset" id="reset" value="Reset" />
Answer by Starx
Basically, when you click the reset button. It will be responsible for clearing the fields, not the label. Normally, jquery validate plugin, keeps its validation messages in labels. So in order to clear them, use
$('label.error').remove();
call this on the click of reset button
where it is needed.