sunnyview
08-27-2002, 10:01 AM
When you click 'OK' to the message telling you that you have to complete a field, it instantly submits the form there and then, before you have had a chance to complete it. It does this for every field left blank.
Anybody???
<HTML>
<HEAD>
<script language="JavaScript">
<!--
// Function to validate the form.
function ProcessForm()
{
var Proceed = 1;
var Message;
var FocusField;
while (Proceed == 1)
{
if (!document.Validation.Name.value)
{
Message = "You must enter your name.";
FocusField = "Name";
Proceed = 0;
break;
}
if (document.Validation.AgeGroup.selectedIndex==0)
{
Message = "You must select your age group.";
FocusField = "AgeGroup";
Proceed = 0;
break;
}
var Address = document.Validation.Address.value
if (Address.length==0)
{
Message = "You must enter your address.";
FocusField = "Address";
Proceed = 0;
break;
}
var CityListLen = 4;
var SelectProceed = 0;
for (i=0; i<=(CityListLen - 1); i++)
{
if (document.Validation.City[i].selected)
{
SelectProceed = 1;
break;
}
}
if (SelectProceed == 0)
{
Message = "You must select at least one city.";
FocusField = "City";
Proceed = 0;
break;
}
var SkillListLen = 4;
var CheckboxProceed = 0;
for (i=0; i<=(SkillListLen - 1); i++)
{
if (document.Validation.Skill[i].checked)
{
CheckboxProceed = 1;
break;
}
}
if (CheckboxProceed == 0)
{
Message = "You must select at least one skill.";
FocusField = "";
Proceed = 0;
break;
}
if (document.Validation.USBorn[1].checked)
{
if (!document.Validation.CountryBorn.value)
{
Message = "If you weren't born in the US, you must enter the country in which you were born.";
FocusField = "CountryBorn";
Proceed = 0;
break;
}
}
break;
}
if (Proceed == 1)
{
alert("The form has been successfully completed.");
}
else
{
alert( Message );
if (FocusField != "")
{
eval("document.Validation." + FocusField + ".focus()");
}
}
}
//-->
</script>
</HEAD>
<BODY>
<p><i>* required fields</i></p>
<FORM ACTION="http://homepages.paradise.net.nz/cgi-bin/mailto" METHOD="POST" name="Validation">
<INPUT NAME="recipient" TYPE="HIDDEN" VALUE="mice@paradise.net.nz">
<p>
<table>
<tr>
<td><span class="label">Name:*</span></td>
<td><input type="text" name="Name"></td>
</tr>
<tr>
<td><span class="label">Age Group:*</span></td>
<td>
<select name="AgeGroup">
<option value="">Select Age Group
<option value="Under 18">Under 18
<option value="18-24">18-24
<option value="25-29">25-29
<option value="30-39">30-39
<option value="40 +">40 +
</select>
</td>
</tr>
<tr>
<td colspan="2"><span class="label">Address:*</span></td>
</tr>
<tr>
<td colspan="2"><textarea name="Address" cols="25" rows="3" wrap="virtual"></textarea></td>
</tr>
<tr>
<td colspan="2">
<table border="0">
<tr>
<td valign="top"><nobr><b>Select at least one city:*</b> </nobr></td>
<td valign="top"><b>Skill(s):*</b></td>
</tr>
<tr>
<td valign="top">
<select name="City" size="4" multiple>
<option value="Chicago">Chicago
<option value="Los Angeles">Los Angeles
<option value="New York">New York
<option value="Washington DC">Washington DC
</select>
</td>
<td valign="top">
<input type="checkbox" name="Skill" value="ASP">ASP<br>
<input type="checkbox" name="Skill" value="ColdFusion">ColdFusion<br>
<input type="checkbox" name="Skill" value="HTML">HTML<br>
<input type="checkbox" name="Skill" value="JavaScript">JavaScript<br>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"><b>Were you born in the US?*</b></td>
</tr>
<tr>
<td colspan="2"><nobr><input type="radio" name="USBorn" value="1" checked>Yes <input type="radio"
name="USBorn" value="0">No</nobr></td>
</tr>
<tr>
<td colspan="2"><b>If "No", please enter the country.</b></td>
</tr>
<tr>
<td colspan="2"><input type="text" name="CountryBorn"></td>
</tr>
<tr>
<td colspan="2" align="center">
<table border="0">
<tr>
<td><input type="submit" value="Send booking" onClick="ProcessForm()"></td>
<td><input type="reset" value="Clear" width="75" style="width:75"></td>
</tr>
</table>
</td>
</tr>
</table>
</p>
</form>
<table border="0">
<tr>
<td><a href="source_code.cfm?CodeID=13"><img src="/graphics/btn_viewsource.gif" border="0"></a></td>
<td><a href="/downloads/FormValidation.zip"><img src="/graphics/btn_download.gif" border="0"></a></td>
<td><a href="javascript:history.go(-1)"><img src="/graphics/btn_back.gif" border="0"></a></td>
</tr>
</table>
<p> </p>
</td>
</tr>
<tr>
<td valign="bottom" align="center">
<p><b>Buy My Book!</b></p>
<a
href="http://www.amazon.com/exec/obidos/ASIN/0782141242/qid=1029592042/sr=1-3/ref=sr_1_3/103-6285903-8323001"
target="_new"><img src="/graphics/MasteringSmall.jpg" border="0" alt="Mastering ColdFusion MX"></a>
<p class="footer">Available 9/13/2002</p>
<p> </p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#ff6600"><img src="/graphics/spacer.gif" height="1" width="1"></td>
</tr>
<tr>
<td><img src="/graphics/spacer.gif" height="5" width="1"></td>
</tr>
<tr>
<td class="footer"> Copyright © 1997 - 2002 WebTricks.com</td>
</tr>
<tr>
<td><img src="/graphics/spacer.gif" height="10" width="1"></td>
</tr>
<tr>
<td class="footer"> <a href="http://www.limitedreality.com"><img
src="/graphics/LimitedRealityBanner.gif" border="0" alt="Limited Reality LLC"></a></td>
</tr>
</table>
</body>
</html>
:) :confused:
Anybody???
<HTML>
<HEAD>
<script language="JavaScript">
<!--
// Function to validate the form.
function ProcessForm()
{
var Proceed = 1;
var Message;
var FocusField;
while (Proceed == 1)
{
if (!document.Validation.Name.value)
{
Message = "You must enter your name.";
FocusField = "Name";
Proceed = 0;
break;
}
if (document.Validation.AgeGroup.selectedIndex==0)
{
Message = "You must select your age group.";
FocusField = "AgeGroup";
Proceed = 0;
break;
}
var Address = document.Validation.Address.value
if (Address.length==0)
{
Message = "You must enter your address.";
FocusField = "Address";
Proceed = 0;
break;
}
var CityListLen = 4;
var SelectProceed = 0;
for (i=0; i<=(CityListLen - 1); i++)
{
if (document.Validation.City[i].selected)
{
SelectProceed = 1;
break;
}
}
if (SelectProceed == 0)
{
Message = "You must select at least one city.";
FocusField = "City";
Proceed = 0;
break;
}
var SkillListLen = 4;
var CheckboxProceed = 0;
for (i=0; i<=(SkillListLen - 1); i++)
{
if (document.Validation.Skill[i].checked)
{
CheckboxProceed = 1;
break;
}
}
if (CheckboxProceed == 0)
{
Message = "You must select at least one skill.";
FocusField = "";
Proceed = 0;
break;
}
if (document.Validation.USBorn[1].checked)
{
if (!document.Validation.CountryBorn.value)
{
Message = "If you weren't born in the US, you must enter the country in which you were born.";
FocusField = "CountryBorn";
Proceed = 0;
break;
}
}
break;
}
if (Proceed == 1)
{
alert("The form has been successfully completed.");
}
else
{
alert( Message );
if (FocusField != "")
{
eval("document.Validation." + FocusField + ".focus()");
}
}
}
//-->
</script>
</HEAD>
<BODY>
<p><i>* required fields</i></p>
<FORM ACTION="http://homepages.paradise.net.nz/cgi-bin/mailto" METHOD="POST" name="Validation">
<INPUT NAME="recipient" TYPE="HIDDEN" VALUE="mice@paradise.net.nz">
<p>
<table>
<tr>
<td><span class="label">Name:*</span></td>
<td><input type="text" name="Name"></td>
</tr>
<tr>
<td><span class="label">Age Group:*</span></td>
<td>
<select name="AgeGroup">
<option value="">Select Age Group
<option value="Under 18">Under 18
<option value="18-24">18-24
<option value="25-29">25-29
<option value="30-39">30-39
<option value="40 +">40 +
</select>
</td>
</tr>
<tr>
<td colspan="2"><span class="label">Address:*</span></td>
</tr>
<tr>
<td colspan="2"><textarea name="Address" cols="25" rows="3" wrap="virtual"></textarea></td>
</tr>
<tr>
<td colspan="2">
<table border="0">
<tr>
<td valign="top"><nobr><b>Select at least one city:*</b> </nobr></td>
<td valign="top"><b>Skill(s):*</b></td>
</tr>
<tr>
<td valign="top">
<select name="City" size="4" multiple>
<option value="Chicago">Chicago
<option value="Los Angeles">Los Angeles
<option value="New York">New York
<option value="Washington DC">Washington DC
</select>
</td>
<td valign="top">
<input type="checkbox" name="Skill" value="ASP">ASP<br>
<input type="checkbox" name="Skill" value="ColdFusion">ColdFusion<br>
<input type="checkbox" name="Skill" value="HTML">HTML<br>
<input type="checkbox" name="Skill" value="JavaScript">JavaScript<br>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"><b>Were you born in the US?*</b></td>
</tr>
<tr>
<td colspan="2"><nobr><input type="radio" name="USBorn" value="1" checked>Yes <input type="radio"
name="USBorn" value="0">No</nobr></td>
</tr>
<tr>
<td colspan="2"><b>If "No", please enter the country.</b></td>
</tr>
<tr>
<td colspan="2"><input type="text" name="CountryBorn"></td>
</tr>
<tr>
<td colspan="2" align="center">
<table border="0">
<tr>
<td><input type="submit" value="Send booking" onClick="ProcessForm()"></td>
<td><input type="reset" value="Clear" width="75" style="width:75"></td>
</tr>
</table>
</td>
</tr>
</table>
</p>
</form>
<table border="0">
<tr>
<td><a href="source_code.cfm?CodeID=13"><img src="/graphics/btn_viewsource.gif" border="0"></a></td>
<td><a href="/downloads/FormValidation.zip"><img src="/graphics/btn_download.gif" border="0"></a></td>
<td><a href="javascript:history.go(-1)"><img src="/graphics/btn_back.gif" border="0"></a></td>
</tr>
</table>
<p> </p>
</td>
</tr>
<tr>
<td valign="bottom" align="center">
<p><b>Buy My Book!</b></p>
<a
href="http://www.amazon.com/exec/obidos/ASIN/0782141242/qid=1029592042/sr=1-3/ref=sr_1_3/103-6285903-8323001"
target="_new"><img src="/graphics/MasteringSmall.jpg" border="0" alt="Mastering ColdFusion MX"></a>
<p class="footer">Available 9/13/2002</p>
<p> </p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#ff6600"><img src="/graphics/spacer.gif" height="1" width="1"></td>
</tr>
<tr>
<td><img src="/graphics/spacer.gif" height="5" width="1"></td>
</tr>
<tr>
<td class="footer"> Copyright © 1997 - 2002 WebTricks.com</td>
</tr>
<tr>
<td><img src="/graphics/spacer.gif" height="10" width="1"></td>
</tr>
<tr>
<td class="footer"> <a href="http://www.limitedreality.com"><img
src="/graphics/LimitedRealityBanner.gif" border="0" alt="Limited Reality LLC"></a></td>
</tr>
</table>
</body>
</html>
:) :confused: