Hi Everyone,
My name is Tim and I have an assignment that I have completed but I can't seem to figure out why I can't validate one field or the other. The "Name" fields are required and that part of the validation works, but also required are the "Address" OR the "Email" fields. The form submits if only the "Address" field and the "Name" fields are completed but the form will not submit if only the "Email" field and the "Name" fields are completed. This is my problem, the form should submit if the "Name" fields AND EITHER of the "Address" or "Email" fields are completed. I want to say thank you in advance for any help offered, I have been struggling with this code for two days now and just can't seem to figure out what I am missing or where I am going wrong.
Here is the code:
CODE
<html>
<head>
<!--
Timothy Shannon
WEB406 - Week 4
Individual Assignment
Complete Change Request - #2
on Service Request - SR-kf-011
-->
<!--
Page title
-->
<title>Kudler Fine Foods Specials and Events Mailing List Registration Form</title>
<script type="text/javascript">
<!-- Form validation -->
function submitForm() {
if (document.forms[0].fname.value == ""
|| document.forms[0].lname.value == "") {
window.alert("You must enter your first and last names.");
return false;
}
else
if (document.forms[0].address.value == "") {
window.alert("You must enter your mailing address or email address.");
return false;
}
else
if (document.forms[0].email.value == "")
return true;
}
</script>
</head>
<form name="request" id="request" action="FormProcessor.html"
onsubmit="return submitForm();"
onreset="return confirmReset();"
enctype="application/x-www-form-urlelncoded">
<table border="0" cellspacing="0" cellpadding="5" width="620" >
<thead style="font-family: times-new roman">
<!--
Header and logo
-->
<tr>
<td valign="top" width="180" rowspan="2">
<img src="Kudler.jpg" alt="kudler" width="375" height="200" >
</td>
<td style="font-size: 2.2em; color: black; font-weight: bold; font-style: italic"
valign="top" align="center" >
Kudler Fine Foods Specials and Events Mailing List Registration
</td>
</tr>
</thead>
<!-- Customer information header -->
<tr>
<td style="font-family: times-new roman; font-size: large; font-weight: bold"
colspan="2" width="100%">
Customer Information
</td>
</tr>
<tr>
<td style="font-family: times-new roman; color: red; font-size: small; font-style: italic"
colspan="2" width="100%">
* Required
** Either is required
</td>
</tr>
<tr>
<td colspan="2">
<hr style="color: red; background-color: red; height: 3" >
</td>
</tr>
<!-- Input fields -->
<tr>
<td valign="top" colspan="2">
<table>
<tr>
<td width="50"><label for="fname">First</label></td>
<td><input type="text" name="fname" id="fname" size="30" ><label style="color: red">*</label></td>
<td width="50"><label for ="lname">Last</label></td>
<td><input type="text" name="lname" id="lname" size="30" ><label style="color: red">*</label></td>
</tr>
<tr>
<td width="100"><label for ="address">Address</label></td>
<td><input type="text" name="address" id="address" size="60" ><label style="color: red">**</label></td>
</tr>
<tr>
<td><label for="phone">Phone</label></td>
<td><input type="text" name="phone" id="phone" size="12" >
</td>
</tr>
<tr>
<td><label for="email">Email Address</label></td>
<td><input type="text" name="email" id="email" size="40" ><label style="color: red">**</label></td>
</tr>
</table>
</td>
<tr>
<td valign="top">
<input type="checkbox" name="Purpose" id="mail" value="Mailing list" >
<label for="mail">Add me to your Mailing List</label><br >
</td>
</tr>
<tr>
<td colspan="2">
<hr style="color: red; background-color: red; height: 3" >
</td>
</tr>
<!--
Customer comments
-->
<tr>
<td width="100" valign="top">
<label for="comments">Comments</label>
</td>
<td valign="top">
<textarea name="comments" id="comments" rows="6" cols="40">
</textarea>
</td>
</tr>
<!-- Register/cancel buttons -->
<tr>
<td valign="top" colspan="2" align="center">
<input type="Submit" value="Register" >
<input type="reset" value="Cancel" >
</td>
</tr>
<!-- Company name and locations -->
<tr style="background-color: red">
<td colspan="2" align="center" valign="bottom">
<address style="font-family: times-new roman; font-size: 0.6em; font-style: normal; font-size: small; color: black">
Kudler Fine Foods ˇ Shopping the World for the Finest Foods ˇ La Jolla ˇ Del Mar ˇ Encinitas ˇ
</address>
</td>
</tr>
</table>
</form>
</html>
Thank you again in advance for any help offered, this site has been very helpful to me in the past, not just by searching on topics, but by getting answers to questions when I've been stumped as well.
"Pulling my hair out!" :-)
Tim