Arc
10-17-2003, 05:04 PM
Hi. I am wondering how to stop a form from being submitted once an error has been raised. I have a Validate function that gives an error if any of the fields aren't correct. The problem is the form submits even if there is an error.
I am using the OnSubmit of the form tag like so
<form name="form1" method="post" action="addlog2.php" onSubmit="Validate()">
and my Validate function looks like so
<script language="JavaScript" type="text/JavaScript">
function Validate(){
var errormsg = "Please make these corrections.";
if(document.form.selCategory.value == "*Select Category*") errormsg += "\n -Select a Category.";
if(document.form.txtCustomer.value == "") errormsg += "\n -Enter a Customer Name.";
if(document.form.txtDeal.value == "") errormsg += "\n -Enter a Deal Number.";
if(document.form.txtStockNum.value == "") errormsg += "\n -Enter a Stock Number.";
if(isNaN(document.form.txtYear.value) || document.form.txtYear.value.Length<4) errormsg += "\n -Enter a valid Year i.e.(1998).";
if(document.form.txtMake.value == "") errormsg += "\n -Enter a Make.";
if(document.form.txtSalesman1.value == "") errormsg += "\n -Enter a name for Salesman1.";
if(document.form.txtSource.value == "") errormsg += "\n -Enter a Source.";
if(isNaN(document.form.txtFinance.value) || document.form.txtFinance.value=="") errormsg += "\n -Enter a valid Finance Income amount. i.e. (1000)";
if(isNaN(document.form.txtVSC.value) || document.form.txtVSC.value=="") errormsg += "\n -Enter a valid VSC Income amount. i.e. (1000)";
if(isNaN(document.form.txtLife.value) || document.form.txtLife.value=="") errormsg += "\n -Enter a valid Life Income amount. i.e. (1000)";
if(isNaN(document.form.txtDisability.value) || document.form.txtDisability.value=="") errormsg += "\n -Enter a valid Disability Income amount. i.e. (1000)";
if(isNaN(document.form.txtGAP.value) || document.form.txtGAP.value=="") errormsg += "\n -Enter a valid GAP Income amount. i.e. (1000)";
if(isNaN(document.form.txtETCH.value) || document.form.txtETCH.value=="") errormsg += "\n -Enter a valid YETCH Income amount. i.e. (1000)";
if(document.form.txtFandI.value == "") errormsg += "\n -Enter a F&I Manager name.";
if(document.form.txtSales.value == "") errormsg += "\n -Enter a Sales Manager name.";
if(errormsg != "Please make these corrections."){
alert(errormsg);
}
}//end function
//-->
</script>
Is there anything I can put in that function to tell the form to not submit?
If I use the Submit buttons OnMouseDown event I will get the error message and the form won;t submit. But the problem with that is the user can still use the Enter button on the keyboard to submit the form.
Thanks!:D
I am using the OnSubmit of the form tag like so
<form name="form1" method="post" action="addlog2.php" onSubmit="Validate()">
and my Validate function looks like so
<script language="JavaScript" type="text/JavaScript">
function Validate(){
var errormsg = "Please make these corrections.";
if(document.form.selCategory.value == "*Select Category*") errormsg += "\n -Select a Category.";
if(document.form.txtCustomer.value == "") errormsg += "\n -Enter a Customer Name.";
if(document.form.txtDeal.value == "") errormsg += "\n -Enter a Deal Number.";
if(document.form.txtStockNum.value == "") errormsg += "\n -Enter a Stock Number.";
if(isNaN(document.form.txtYear.value) || document.form.txtYear.value.Length<4) errormsg += "\n -Enter a valid Year i.e.(1998).";
if(document.form.txtMake.value == "") errormsg += "\n -Enter a Make.";
if(document.form.txtSalesman1.value == "") errormsg += "\n -Enter a name for Salesman1.";
if(document.form.txtSource.value == "") errormsg += "\n -Enter a Source.";
if(isNaN(document.form.txtFinance.value) || document.form.txtFinance.value=="") errormsg += "\n -Enter a valid Finance Income amount. i.e. (1000)";
if(isNaN(document.form.txtVSC.value) || document.form.txtVSC.value=="") errormsg += "\n -Enter a valid VSC Income amount. i.e. (1000)";
if(isNaN(document.form.txtLife.value) || document.form.txtLife.value=="") errormsg += "\n -Enter a valid Life Income amount. i.e. (1000)";
if(isNaN(document.form.txtDisability.value) || document.form.txtDisability.value=="") errormsg += "\n -Enter a valid Disability Income amount. i.e. (1000)";
if(isNaN(document.form.txtGAP.value) || document.form.txtGAP.value=="") errormsg += "\n -Enter a valid GAP Income amount. i.e. (1000)";
if(isNaN(document.form.txtETCH.value) || document.form.txtETCH.value=="") errormsg += "\n -Enter a valid YETCH Income amount. i.e. (1000)";
if(document.form.txtFandI.value == "") errormsg += "\n -Enter a F&I Manager name.";
if(document.form.txtSales.value == "") errormsg += "\n -Enter a Sales Manager name.";
if(errormsg != "Please make these corrections."){
alert(errormsg);
}
}//end function
//-->
</script>
Is there anything I can put in that function to tell the form to not submit?
If I use the Submit buttons OnMouseDown event I will get the error message and the form won;t submit. But the problem with that is the user can still use the Enter button on the keyboard to submit the form.
Thanks!:D