开发者

Error message not get cleared while clicking the reset button

开发者 https://www.devze.com 2023-03-15 09:41 出处:网络
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.

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" /&g开发者_运维百科t;   


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.


Try hiding them by calling CSS hide property on your error DIV's when you press reset button

0

精彩评论

暂无评论...
验证码 换一张
取 消