0

On submit button click I need to check the validation if its returns true. I need to submit the form. But when it returns false also the form gets submitted and the event SaveProjects() gets called. How can I prevent the form submission when CheckValidation() returns false?

 <script type="text/javascript> 
   function CheckValidation()
      {
       alert();
      return false;
      }

</script>
    @using (@Ajax.BeginForm("SaveProjects", "Projects", null, new AjaxOptions { OnSuccess =     "OnSuccessProject", HttpMethod = "post" }, new { id = "ProjectsForm" }))
       {     <div class="outerBox" id="divProjectCreate">

      @Html.Partial("../Projects/_CreateOrEdit", Model)
         <div class="row centerAlign">
          <input type="submit" value="Save" id="btnSaveProjects"  onclick="CheckValidation()"/>
         <input type="button" value="Cancel" id="btnCancel" />
         </div>

        </div>

}
tereško
  • 58,060
  • 25
  • 98
  • 150
user2156088
  • 2,350
  • 5
  • 20
  • 24

1 Answers1

1

you can do

   $('#target').submit(function() {
      alert('Handler for .submit() called.');
      return CheckValidation();
    });
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307