javascript - Prevent form submission when validation fails on submit button click -
on submit button click need check validation if returns true. need submit form. when returns false form gets submitted , event saveprojects() gets called. how can prevent 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> }
you can do
$('#target').submit(function() { alert('handler .submit() called.'); return checkvalidation(); });
Comments
Post a Comment