The function is supposed to restrict the user from choosing too many categories. The categories are presented as checkboxes. There are two different sets of checkboxes but both validations really do the same thing.
I have provided the function below and below that the form in its entirety.
With Internet Explorer the function works as expected. With FF the function allows the user to go to Success.html no matter how many boxes are checked.
I do have the whole thing set up on a URL but I am not sure if I can post that here.
I would appreciate any help on this.
function validate(form) {
// This function throws a syntax error when saving. It is false and it works. Do not be afraid.
var totalDes = 0;
var DesignationsAllowed = 2;
var max = form1.CheckboxDes.length;
for (var idx = 0; idx < max; idx++) {
if (eval("document.form1.CheckboxDes[" + idx + "].checked") == true) {
totalDes += 1;
}
}
if (totalDes > DesignationsAllowed) {
alert("You selected " + totalDes + " designations. You are allowed " + DesignationsAllowed);
return false;}
var totalSpec = 0;
var SpecialtiesAllowed = 4;
var max = form1.CheckboxSpec.length;
for (var idx = 0; idx < max; idx++) {
if (eval("document.form1.CheckboxSpec[" + idx + "].checked") == true) {
totalSpec += 1;
}
}
if (totalSpec > SpecialtiesAllowed) {
alert("You selected " + totalSpec + " Specialties/Problems. You are allowed " + SpecialtiesAllowed);
return false;}
return true;
}
<FORM ACTION="Success.html" name="form1" onSubmit="return validate(this.form)">
<h1>Designations</h1>
<table align="center" cellpadding="5" cellspacing="5" width="95%">
<table>
<tr align="center" valign="top">
<td>
<tr>
<td height="25" valign="middle" width="200" ><input checked name="CheckboxDes" type="checkbox" value="1">
Consulting<br>
</td>
<td height="25" valign="middle" width="200" ><input checked name="CheckboxDes" type="checkbox" value="3">
Therapist<br>
</td>
<td height="25" valign="middle" width="200" ><input checked name="CheckboxDes" type="checkbox" value="2">
Hypnotist<br>
</td>
<td > </td>
</tr>
</td>
</tr>
<tr align="center" valign="top">
<td>
<tr>
<td height="25" valign="middle" width="200" ><input checked name="CheckboxDes" type="checkbox" value="6">
Trainer<br>
</td>
<td height="25" valign="middle" width="200" ><input name="CheckboxDes" type="checkbox" value="4">
Practitioner<br>
</td>
<td height="25" valign="middle" width="200" ><input name="CheckboxDes" type="checkbox" value="5">
Stage<br>
</td>
<td > </td>
</tr>
</td>
</tr>
</table>
</table>
<h1>Problems</h1>
<table align="center" cellpadding="5" cellspacing="5" width="80%">
<table>
<tr align="center" valign="top">
<td>
<tr>
<td height="25" valign="middle" width="200" ><input name="CheckboxSpec" type="checkbox" value="20">
5-Path/7-Path<br>
</td>
<td height="25" valign="middle" width="200" ><input checked name="CheckboxSpec" type="checkbox" value="26">
Accelerated Learning
<br>
</td>
<td height="25" valign="middle" width="200" ><input name="CheckboxSpec" type="checkbox" value="27">
Habits<br>
</td>
<td > </td>
</tr>
</td>
</tr>
<tr align="center" valign="top">
<td>
<tr>
<td height="25" valign="middle" width="200" ><input name="CheckboxSpec" type="checkbox" value="28">
Anxiety and Stress<br>
</td>
<td height="25" valign="middle" width="200" ><input checked name="CheckboxSpec" type="checkbox" value="29">
Children<br>
</td>
<td height="25" valign="middle" width="200" ><input name="CheckboxSpec" type="checkbox" value="30">
Confidence<br>
</td>
<td > </td>
</tr>
</td>
</tr>
<tr align="center" valign="top" align="80%">
<td>
<tr>
<td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="31">
Creativity<br>
</td>
<td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="15">
Diabetes<br>
</td>
<td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="32">
Esoteric<br>
</td>
<td > </td>
</tr>
</td>
</tr>
<tr align="center" valign="top">
<td>
<tr>
<td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="11">
Fears<br>
</td>
<td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="33">
Financial<br>
</td>
<td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="21">
Imagery<br>
</td>
<td > </td>
</tr>
</td>
</tr>
<tr align="center" valign="top">
<td>
<tr>
<td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="34">
Health<br>
</td>
<td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="16">
Birthing<br>
</td>
<td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="14">
Relationships<br>
</td>
<td > </td>
</tr>
</td>
</tr>
</table>
</table>
<div align="center">
<INPUT TYPE=SUBMIT VALUE="Submit">
</div>
</FORM>


Reply With Quote
Bookmarks