Click to See Complete Forum and Search --> : Form Validation problems


mplutodh1
05-30-2003, 04:45 PM
Can someone help me with this, I am trying to get this form to validate the fields by checking to see the length of the valu within each field. I also need the form to email me the results. Its crude, and this is how its going to have to work. I am also having trouble with the radio buttons, how do i check to see if something is checked?

Thanks.

<script>
function confirmReset() {
var resetForm = confirm("Are you sure you want to reset the form?");
if (resetForm == true)
return true;
return false;
}

function validate() {
if (document.order.firstname.value.length < 2) {
alert("Please enter your full first name.");
return false;
}
if (document.order.lastname.value.length < 2) {
alert("Please enter your full last name.");
return false;
}
if (document.order.street.value.length < 5) {
alert("Please enter your full street address.");
return false;
}
if (document.order.city.value.length < 2) {
alert("Please enter your full city name.");
return false;
}
if (document.order.state.value.length < 2) {
alert("Please enter your state.");
return false;
}
if (document.order.zip.value.length < 5) {
alert("Please enter your zip code.");
return false;
}
if (document.order.phone.value.length < 7) {
alert("Please enter your phone number.");
return false;
}
if (document.order.email.value.length < 5) {
alert("Please enter your email.");
return false;
}
if (document.order.form.value.length < 1) {
alert("Please enter your email.");
return false;
}
return true;
}
</script>



<form name="order" id="order" onSubmit="return validate(); action="mailto:pludem@cc.wwu.edu" enctype="text/plain" method="POST" onReset="return confirmReset();">


<table border="0" width="250" cellspacing="0" cellpadding="0">
<tr>
<td width="50%"><b>First Name:</b></td>
<td width="50%"><input name="firstname" id="firstname"></td>
</tr>
<tr>
<td width="50%"><b>Last Name:</b></td>
<td width="50%"><input name="lastname" id="lastname"></td>
</tr>
<tr>
<td width="50%"><b>Street Address:</b></td>
<td width="50%"><input name="street" id="street"></td>
</tr>
<tr>
<td width="50%"><b>City:</b></td>
<td width="50%"><input name="city" id="city"></td>
</tr>
<tr>
<td width="50%"><b>State:</b></td>
<td width="50%"><input name="state" id="state" size="3"></td>
</tr>
<tr>
<td width="50%"><b>Zip:</b></td>
<td width="50%"><input name="zip" id="zip" size="10"></td>
</tr>
<tr>
<td width="50%"><b>Phone:</b></td>
<td width="50%"><input name="phone" id="phone"></td>
</tr>
<tr>
<td width="50%"><b>Email:</b></td>
<td width="50%"><input name="email" id="email"></td>
</tr>
<tr>
<td width="50%" valign="top"><b>Type of Form:</b></td>
<td width="50%">
<input type="radio" name="form" value="form1">Form1<br>
<input type="radio" name="form" value="form2">Form2<br>
<input type="radio" name="form" value="form3">Form3</td>
</tr>
<tr>
<td colspan="2"><br><br><div align="right"><input TYPE="SUBMIT" VALUE="Submit">&nbsp;&nbsp;&nbsp;<input TYPE="RESET"

VALUE="Reset"></div></td>
</tr>
</table>

khalidali63
05-30-2003, 05:03 PM
Take a look at this form,and see if this validation helps you understand the conepts..
http://68.145.35.86/skills/javascripts/UltimateFormValidator.html

mplutodh1
05-30-2003, 05:26 PM
Originally posted by khalidali63
Take a look at this form,and see if this validation helps you understand the conepts..
http://68.145.35.86/skills/javascripts/UltimateFormValidator.html


Thanks I am going to have to take a closer look at it.

mplutodh1
05-30-2003, 06:07 PM
Originally posted by Dave Clark
For your radio buttons:

<input type="radio" name="form" value="form1">Form1<br>
<input type="radio" name="form" value="form2">Form2<br>
<input type="radio" name="form" value="form3">Form3

you better change the name. Each FORM element already has a property of form and your use of the same name may cause conflicts.

Dave

Good call... didnt even think of that