I have two pieces of javascript that I would like to work together. I have a form that is submitted via ajax, and a form validation script, that I would like to work together to prevent the ajax form submission if the validation fails.
The ajax form submissionscript:
<script type="text/javascript">
$(document).ready(function(){$(".sendName").click(function(){
var jsuser=$("#jsuser").val();
var jemail=$("#jemail").val();
var jusid=$("#jusid").val();
$.post("recomend.php",{jsuser:jsuser,jusid:jusid,jemail:jemail},function(data){$("#loadName")
.html(data)
.effect( bounce , { times: 5, distance: 30 }, 300);
});
});
});
$( #start ).click(function() {
$( #effect ).toggle( fast , function() {
});
});
</script>
This code works perfectly, and the form is submitted.
我也有部分有效的验证法。 如果输入错误信息,错误信息就会在实地出现,但形式仍然可以提交。
通常形式的验证法也一样:
<form method="post" action="formprocess.php" name="form1" id="form1" onsubmit="return validate(this)">
因此,我需要知道如何做到:
onsubmit="return validate(this)"
in the ajax submission code, and not submit the form if there are errors.