dcslick
06-19-2005, 11:22 PM
Hello,
I have to do a simple form with javascript validation. The vaildation is that all fields are filled in, at this point I have no idea why its not working its probably in front of me but I am too fustrated. Also I would like my email address field to validate the @ and . I had it working for another form but I cant on this one.
Any help would be appreciated
Thanks
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>eform</title>
<style>
body {background-color: yellow}
.required {color:red}
h1 {color: rgb(0,0,255)}
</style>
<script type="text/javascript">
<!--
function validateForm()
{
var isValid = false;
if (document.mail.fullname.value == '')
{
alert('Please enter your name.');
document.mail.fullname.focus();
}
else if (document.mail.email.value == '')
{
alert('Please enter your email address.');
document.mail.email.focus();
}
else if (document.mail.phone.value == '')
{
alert('Please enter your phone number.');
document.mail.phone.focus();
}
else if (document.mail.mf[0].checked==false &&
document.mail.mf[1].checked==false)
{
alert('Are you a Male or Female.');
document.mail.mf[0].focus();
}
else if (document.mail.os[0].checked==false &&
document.mail.os[1].checked==false)
{
alert('Please Select your Favorite OS.');
document.mail.os[0].focus();
}
else if (document.mail.color[0].checked==false &&
document.mail.color[1].checked==false &&
document.mail.color[2].checked==false &&
document.mail.color[3].checked==false &&
document.mail.color[4].checked==false &&
document.mail.color[5].checked==false)
{
alert('Please select a color.');
document.mail.color[0].focus();
}
else if (document.mail.kids.checked==false &&
document.mail.dogs.checked==false &&
document.mail.cats.checked==false &&
document.mail.alligator.checked==false)
{
alert('Please select a pet or family.');
document.mail.kids.focus();
}
else if (document.mail.message.value == '')
{
alert('Please enter a message!');
document.mail.message.focus();
}
else
{
isValid = true;
}
return isValid
}
//-->
</script>
</head>
<body>
<LEFT>
<FORM NAME = "mail" ACTION = "mailto:dougcc@cox.net" METHOD = "POST" ENCTYPE = "text/plain">
<INPUT TYPE = "hidden" NAME = "info">
<TABLE BORDER = 0 CELLPADDING = 5 CELLSPACING = 0>
<tr>
<td colspan="2" align="center"><h1>Your Feedback</h1></td>
</tr>
<TR>
<td>Your Name<span class="required">*</span>
<P>
<INPUT TYPE = "TEXT" NAME = "fullname">
</TD>
<td>Your Email Address<span class="required">*</span>
<P>
<INPUT TYPE = "TEXT" NAME = "email">
</TD>
</TR>
<TR>
<TD>
Your Phone Number<span class="required">*</span>
<P>
<INPUT TYPE = "TEXT" NAME = "phone">
<td> </TD>
</TR>
<TR>
<td>Male or Female<span class="required">*</span>
<P>
<input type="radio" name="mf" value="male">Male<br>
<input type="radio" name="mf" value="female">Female<br>
</TR>
<TR>
<td>MS Windows or Unix:<span class="required">*</span>:
<p>
<input type="radio" name="os" value="win">MS Windows<br>
<input type="radio" name="os" value="unix">Unix<br>
</TR>
<tr>
<td>Color:<span class="required">*</span></td>
<td>
<select name="color">
<option value="">--- Select your favorite color ---
<option value="rd">Red
<option value="be">Blue
<option value="oe">Orange
<option value="bk">Black
<option value="gn">Green
<option value="yw">Yellow
</select>
</td>
</tr>
<td valign="top">Family and Pets:<span class="required">*</span></td>
<td>
<input type="checkbox" name="Kids" value="kids">Kids<br>
<input type="checkbox" name="Dogs" value="dogs">Dogs<br>
<input type="checkbox" name="Cats" value="cats">Cats<br>
<input type="checkbox" name="Alligator" value="alligator">Alligator
</td>
</tr>
<TR>
<TD COLSPAN = "2">
Enter your Message:
<P>
<TEXTAREA ROWS = "8" COLS = "38" NAME = "message">
</TEXTAREA>
</TD>
</TR>
<TR>
<TD COLSPAN = "2">
<INPUT TYPE = "SUBMIT" VALUE = " Submit ">
<INPUT TYPE = "RESET" VALUE = " Reset ">
</TD>
</TR>
</TABLE>
</FORM>
</body>
</html>
I have to do a simple form with javascript validation. The vaildation is that all fields are filled in, at this point I have no idea why its not working its probably in front of me but I am too fustrated. Also I would like my email address field to validate the @ and . I had it working for another form but I cant on this one.
Any help would be appreciated
Thanks
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>eform</title>
<style>
body {background-color: yellow}
.required {color:red}
h1 {color: rgb(0,0,255)}
</style>
<script type="text/javascript">
<!--
function validateForm()
{
var isValid = false;
if (document.mail.fullname.value == '')
{
alert('Please enter your name.');
document.mail.fullname.focus();
}
else if (document.mail.email.value == '')
{
alert('Please enter your email address.');
document.mail.email.focus();
}
else if (document.mail.phone.value == '')
{
alert('Please enter your phone number.');
document.mail.phone.focus();
}
else if (document.mail.mf[0].checked==false &&
document.mail.mf[1].checked==false)
{
alert('Are you a Male or Female.');
document.mail.mf[0].focus();
}
else if (document.mail.os[0].checked==false &&
document.mail.os[1].checked==false)
{
alert('Please Select your Favorite OS.');
document.mail.os[0].focus();
}
else if (document.mail.color[0].checked==false &&
document.mail.color[1].checked==false &&
document.mail.color[2].checked==false &&
document.mail.color[3].checked==false &&
document.mail.color[4].checked==false &&
document.mail.color[5].checked==false)
{
alert('Please select a color.');
document.mail.color[0].focus();
}
else if (document.mail.kids.checked==false &&
document.mail.dogs.checked==false &&
document.mail.cats.checked==false &&
document.mail.alligator.checked==false)
{
alert('Please select a pet or family.');
document.mail.kids.focus();
}
else if (document.mail.message.value == '')
{
alert('Please enter a message!');
document.mail.message.focus();
}
else
{
isValid = true;
}
return isValid
}
//-->
</script>
</head>
<body>
<LEFT>
<FORM NAME = "mail" ACTION = "mailto:dougcc@cox.net" METHOD = "POST" ENCTYPE = "text/plain">
<INPUT TYPE = "hidden" NAME = "info">
<TABLE BORDER = 0 CELLPADDING = 5 CELLSPACING = 0>
<tr>
<td colspan="2" align="center"><h1>Your Feedback</h1></td>
</tr>
<TR>
<td>Your Name<span class="required">*</span>
<P>
<INPUT TYPE = "TEXT" NAME = "fullname">
</TD>
<td>Your Email Address<span class="required">*</span>
<P>
<INPUT TYPE = "TEXT" NAME = "email">
</TD>
</TR>
<TR>
<TD>
Your Phone Number<span class="required">*</span>
<P>
<INPUT TYPE = "TEXT" NAME = "phone">
<td> </TD>
</TR>
<TR>
<td>Male or Female<span class="required">*</span>
<P>
<input type="radio" name="mf" value="male">Male<br>
<input type="radio" name="mf" value="female">Female<br>
</TR>
<TR>
<td>MS Windows or Unix:<span class="required">*</span>:
<p>
<input type="radio" name="os" value="win">MS Windows<br>
<input type="radio" name="os" value="unix">Unix<br>
</TR>
<tr>
<td>Color:<span class="required">*</span></td>
<td>
<select name="color">
<option value="">--- Select your favorite color ---
<option value="rd">Red
<option value="be">Blue
<option value="oe">Orange
<option value="bk">Black
<option value="gn">Green
<option value="yw">Yellow
</select>
</td>
</tr>
<td valign="top">Family and Pets:<span class="required">*</span></td>
<td>
<input type="checkbox" name="Kids" value="kids">Kids<br>
<input type="checkbox" name="Dogs" value="dogs">Dogs<br>
<input type="checkbox" name="Cats" value="cats">Cats<br>
<input type="checkbox" name="Alligator" value="alligator">Alligator
</td>
</tr>
<TR>
<TD COLSPAN = "2">
Enter your Message:
<P>
<TEXTAREA ROWS = "8" COLS = "38" NAME = "message">
</TEXTAREA>
</TD>
</TR>
<TR>
<TD COLSPAN = "2">
<INPUT TYPE = "SUBMIT" VALUE = " Submit ">
<INPUT TYPE = "RESET" VALUE = " Reset ">
</TD>
</TR>
</TABLE>
</FORM>
</body>
</html>