在提交按钮单击时验证失败时阻止表单提交

[英]Prevent form submission when validation fails on submit button click


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?

在提交按钮单击我需要检查验证,如果它返回true。我需要提交表格。但是当它返回false时,表单也会被提交并且事件SaveProjects()被调用。当CheckValidation()返回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>

}

1 个解决方案

#1


1  

you can do

你可以做

   $('#target').submit(function() {
      alert('Handler for .submit() called.');
      return CheckValidation();
    });
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2013/05/02/c8890585e26a0c73774c43f1d18c00d1.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告