I have a form, one of whose questions uses the following HTML code:
<TABLE ALIGN="center" WIDTH="390" BORDER="0" CELLPADDING="0" CELLSPACING="0">
<FORM ACTION="survey8.html" METHOD="POST" onsubmit="return checkit(this);">
<INPUT TYPE="hidden" NAME="uid" VALUE="<? echo $uid; ?>">
<TR><TD VALIGN="top" ALIGN="center">
<FONT FACE="arial,helvetica" SIZE="-1"><B>4. Pick the three (3)
extrusion equipment suppliers you would call first for a new equipment
proposal (Select three only):</B></FONT></TD>
</TR>
<TR><TD ALIGN="center">
<TABLE WIDTH="300">
<TR>
<TD VALIGN="bottom" ALIGN="right"><INPUT TYPE="checkbox" NAME="q6a" VALUE="1"></TD>
<TD VALIGN="bottom" ALIGN="left"><FONT FACE="arial, helvetica"
SIZE="-1"><B>Davis-Standard</B></FONT></TD></TR>
<TR>
<TD VALIGN="bottom" ALIGN="right"><INPUT TYPE="checkbox" NAME="q6b" VALUE="1"></TD>
<TD VALIGN="bottom" ALIGN="left"><FONT FACE="arial, helvetica"
SIZE="-1"><B>Gloucester</B></FONT></TD></TR>
<TR>
<TD VALIGN="bottom" ALIGN="right"><INPUT TYPE="checkbox" NAME="q6c" VALUE="1"></TD>
<TD VALIGN="bottom" ALIGN="left"><FONT FACE="arial, helvetica"
SIZE="-1"><B>HPM</B></FONT></TD></TR>
<TR>
<TD VALIGN="bottom" ALIGN="right"><INPUT TYPE="checkbox" NAME="q6d" VALUE="1"></TD>
<TD VALIGN="bottom" ALIGN="left"><FONT FACE="arial, helvetica"
SIZE="-1"><B>Kuhne</B></FONT></TD></TR>
<TR>
<TD VALIGN="bottom" ALIGN="right"><INPUT TYPE="checkbox" NAME="q6e" VALUE="1"></TD>
<TD VALIGN="bottom" ALIGN="left"><FONT FACE="arial, helvetica"
SIZE="-1"><B>Merritt</B></FONT></TD></TR>
<TR>
<TD VALIGN="bottom" ALIGN="right"><INPUT TYPE="checkbox" NAME="q6f" VALUE="1"></TD>
<TD VALIGN="bottom" ALIGN="left"><FONT FACE="arial, helvetica"
SIZE="-1"><B>Milacron</B></FONT></TD></TR>
<TR>
<TD VALIGN="bottom" ALIGN="right"><INPUT TYPE="checkbox" NAME="q6g" VALUE="1"></TD>
<TD VALIGN="bottom" ALIGN="left"><FONT FACE="arial, helvetica"
SIZE="-1"><B>PTI</B></FONT></TD></TR>
<TR>
<TD VALIGN="bottom" ALIGN="right"><INPUT TYPE="checkbox" NAME="q6h" VALUE="1"></TD>
<TD VALIGN="bottom" ALIGN="left"><FONT FACE="arial, helvetica"
SIZE="-1"><B>Welex</B></FONT></TD></TR>
<TR>
<TD VALIGN="bottom" ALIGN="right"><INPUT TYPE="checkbox" NAME="q6i" VALUE="1"></TD>
<TD VALIGN="bottom" ALIGN="left"><FONT FACE="arial, helvetica"
SIZE="-1"><B>Other </B></FONT><INPUT TYPE="text" NAME="q6idesc"
SIZE="15"></TD></TR>
</TABLE>
</TD></TR>
<TR><TD HEIGHT="40"> </TD></TR>
<TR>
<TD ALIGN="center" COLSPAN="2">
<FONT FACE="arial, helvetica" SIZE="-1">
<CENTER>
<INPUT TYPE="submit" VALUE="Next >>"></FONT></CENTER>
</TD></TR></FORM>
</TABLE>
As you can see, all of the checkboxes have a different name. I already
have the Javascript validation set so that the user has to check at
least one checkbox to submit the form, and enter a company name in the
text box if the user checked "Other." Here it is:
<SCRIPT language="javascript">
<!-- HIDE
function checkit(aform)
{
if(!(aform.q6a.checked || aform.q6b.checked || aform.q6c.checked
|| aform.q6d.checked || aform.q6e.checked || aform.q6f.checked ||
aform.q6g.checked || aform.q6h.checked || aform.q6i.checked))
{
window.alert("Please answer the question.");
aform.q6a.focus();
aform.q6a.select();
return false;
}
if(aform.q6i.checked && aform.q6idesc.value.length ==0)
{
window.alert("Please name other extrusion equipment supplier.");
aform.q6idesc.focus();
aform.q6idesc.select();
return false;
}
}
//-->
</SCRIPT>
Now, my problem is that the user must not select more than three (3)
checkboxes. How do I code it so that the user gets an alert window
when they try to submit with more than three checkboxes selected?
Thanks for your help! |