JavaScript to validate checkboxes

by "Keith Purtell" <kpurtell(at)vantagemed.com>

 Date:  Fri, 25 Oct 2002 08:31:06 -0500
 To:  <hwg-languages-digest(at)mail.hwg.org>
  todo: View Thread, Original
This JavaScript to validate a form works for all input fields except my checkboxes. What the user
should see when they click the submit button -- assuming they leave form fields blank -- is an alert
box with short messages indicating which fields were left blank. Each of those form fields has it's
own function and "why +=" line, but I removed most of those for the sake of brevity. Here are
snippets; I'd like suggestions on how to make this work correctly. TIA.

function checkffDefine (ffDefine) {
var error = "";
if (ffDefine == false) {
	error = "You did not enter an Enhancement Definition.\n";
	}
return error;
}


function checkWholeForm(form) {
    var why = "";
    why += checkffDefine(form.ffDefine.checked);
    if (why != "") {
       alert(why);
       return false;
	   }
return true;
}


FORM NAME="form" ACTION="page2.htm" METHOD="post" onSubmit="return checkWholeForm(this);"

INPUT TYPE="checkbox" NAME="ffDefine" VALUE="ChangeUserInterface"
 Does the user interface need to change?
INPUT TYPE="checkbox" NAME="ffDefine" VALUE="CaptureNewData"
 Is there new data we need to capture?


Keith Purtell, Web/Network Administrator
VantageMed Operations (Kansas City)
Email:  kpurtell(at)vantagemed.com


CONFIDENTIALITY NOTICE: This email message, including any attachments, is for the sole use of the
intended recipient(s) and may contain confidential and privileged information. Any unauthorized
review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please
contact the sender by reply email and destroy all copies of the original message.

---
[This E-mail scanned for viruses by Declude Virus]

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA