<script type="text/javascript">
$(document).ready(function(){
$('#addprojectform').live('submit', function (e) {
e.preventDefault();
$(".error").remove();
var startdate = $("#startdate").val();
var client = $('#client').val();
var source_lang= $('#source_lang option:selected').length;
var targ_lang = $('#targ_lang option:selected').length;
var qty = $('#qty').val();
var hasError = false;
if(startdate == '') {
$("#startdate").after('<span class="error" style="color: red;">This field is required.</span>');
hasError = true;
}
if(client == '') {
$("#client").after('<span class="error" style="color: red;">This field is required. </span>');
hasError = true;
}
if(!(source_lang)) {
$("#source_lang").after('<span class="error" style="color: red;">This field is required.</span>');
hasError = true;
}
if(!(targ_lang)) {
$("#targ_lang").after('<span class="error" style="color: red;">This field is required.</span>');
hasError = true;
}
if(qty == '') {
$("#qty").after('<span class="error" style="color: red;">This field is required.</span>');
hasError = true;
}
} // if translation
if(hasError == false)
return true;
});
});
</script>
我有这个代码。我想在提交之前验证表格。我无法控制表单何时没有错误。如果没有发现错误,我想提交表单。我添加了这段代码:
if(hasError == false)
return true;
但不提交表格..请任何人都可以帮忙吗?