J
Jon
Hi, I have a form. I have the code, below, to check for certain compulasry
fields. The Submit button has:
onClick="validate(this.form)"
My problem is that the warnings come up fine, but the form still gets
posted. Please can someone advise how I cancel the function if data is
missing?
Thank. Jon
<SCRIPT language="JavaScript" type="text/javascript">
<!--
function validate(x) {
var e = "";
var r = true;
if(x.txtName.value == "") {
e += "\n\nPlease enter a name";
r = false;
}
if(x.txtCompany.value == "") {
e += "\n\nPlease enter a company name";
r = false;
}
if(x.txtPhone.value == "") {
e += "\n\nPlease enter a phone number";
r = false;
}
if(x.txtEmail.value == "") {
e += "\n\nPlease enter an email address";
r = false;
}
if(r == false) {
alert("The following must be completed first:"+e);
}
return r;
}
// -->
</SCRIPT>
fields. The Submit button has:
onClick="validate(this.form)"
My problem is that the warnings come up fine, but the form still gets
posted. Please can someone advise how I cancel the function if data is
missing?
Thank. Jon
<SCRIPT language="JavaScript" type="text/javascript">
<!--
function validate(x) {
var e = "";
var r = true;
if(x.txtName.value == "") {
e += "\n\nPlease enter a name";
r = false;
}
if(x.txtCompany.value == "") {
e += "\n\nPlease enter a company name";
r = false;
}
if(x.txtPhone.value == "") {
e += "\n\nPlease enter a phone number";
r = false;
}
if(x.txtEmail.value == "") {
e += "\n\nPlease enter an email address";
r = false;
}
if(r == false) {
alert("The following must be completed first:"+e);
}
return r;
}
// -->
</SCRIPT>