Confirm dialog should come after validate in jquery

5.5k Views Asked by At

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;
        }else{
            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.

2

There are 2 best solutions below

1
On

perhaps this should help you. Jquery validate onValid.

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

0
On

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>