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.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!