Hi
I create a dynamic list of candidates for a Recruitment Web Site. Besides each name is a checkbox which when selected will signal that that candidate is to be emailed. The following works great when there is more than one candidate in the list. However, if there is only one candidate then 'form.elements['email[]'].length' returns 'undefined' and so the for loop never gets actioned. This then returns the alert message 'Please Select A Candidate To Email' even though the one candidate has had their checkbox ticked. Any ideas? Is this a bug using the PHP dynamic array i.e. email[], or am I missing something in my code? Any help will be greatly appreciated.
echo "<script language=\"JavaScript1.2\">\n";
echo "function checkEmailSelect(form){\n";
echo " var emailbool = false;\n";
echo " for(i=0;i<form.elements['email[]'].length;i++){\n";
echo " alert(form.elements['email[]'].value);\n";
echo " if(form.elements['email[]'].checked){\n";
echo " emailbool = true;\n";
echo " }\n";
echo " }\n";
echo " if(emailbool == false){\n";
echo " alert(\"Please Select A Candidate To Email.\");\n";
echo " }else{\n";
echo " form.submit();\n";
echo " }\n";
echo "}\n";
echo "</script>\n";
//the following is in a while loop
while(dataexists){
echo " <td align=\"center\"> <input type=\"button\" name=\"emails\" value=\"EMAIL\" onclick=\"checkEmailSelect(document.confirm);\"></td>\n";
}