开发者

Confirm dialog should come after validate in jquery

开发者 https://www.devze.com 2023-02-22 21:39 出处:网络
I am using jquery-1.4.4 in struts. I had successfully used the jquery.validate plugin and validated my request form. But since it is a 3 page form, I have to give a confirm dialog box at each page to

I am using jquery-1.4.4 in struts. I had successfully used the jquery.validate plugin and validated my request form. But since it is a 3 page form, I have to give a confirm dialog box at each page to ensure users recheck their form entries.

     $(document).ready(function() {
     :::
      $("#Form1").validate({
      ::
      });
      function onSubmitForm(){
        var vconf = confirm(" You are about to submit, please recheck the the fields");
        if(vconf){
            return true;
        }els开发者_Python百科e{
            return false;
       }
      }
     });

and my submit button

<input type="submit" title="continue filling up the form" value="  Continue  " 
                onclick= "return onSubmitForm();"/>

This first calls my confirm dialog and then does validation, which is not appropriate to first ask the user if he actually wants to continue and then stop them saying that their form is not valid.


i think so you can try this....

<script type="text/javascript">
$(document).ready(function() { 
  $("#Form1").validate({ 
    submitHandler : function(form) {
      if (confirm("You are about to submit, please recheck the the fields?")) {
        form.submit();
      }
    },
    rules: { 
      x: {
        required: true,
      },
      y:{
        required:true,
      }
    }
  })
}); 
</script>


perhaps this should help you. Jquery validate onValid.

Just call the function onSubmitForm() after you submit, and submit the form using javascript.

0

精彩评论

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

关注公众号