I have a form validation script, and I need to add validation for a checkbox called "privacy". <script language="JavaScript"> <!-- function formCheck(formobj){ // Enter name of mandatory fields var fieldRequired = Array("Name", "EmailFrom", "Phone"); // Enter field description to appear in the dialog box var fieldDescription = Array("Name", "Email","Phone Number"); // dialog message var alertMsg = "Please provide us with the following information:\n"; var l_Msg = alertMsg.length; for (var i = 0; i < fieldRequired.length; i++){ var obj = formobj.elements[fieldRequired]; if (obj){ switch(obj.type){ case "select-one": if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){ alertMsg += " - " + fieldDescription + "\n"; } break; case "select-multiple": if (obj.selectedIndex == -1){ alertMsg += " - " + fieldDescription + "\n"; } break; case "text": case "textarea": if (obj.value == "" || obj.value == null){ alertMsg += " - " + fieldDescription + "\n"; } break; default: } if (obj.type == undefined){ var blnchecked = false; for (var j = 0; j < obj.length; j++){ if (obj[j].checked){ blnchecked = true; } } if (!blnchecked){ alertMsg += " - " + fieldDescription + "\n"; } } } } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } // --> </script> First working answer posted below receives $5 via PayPal...
Hi, pcoulter I don't know what you are validating. But in the script you provided, after case "text":, you missed a break;
Hello, By validation, I just need to make sure the checkbox is selected (for terms and conditions)? Any help (I'm not a programmer)... Thanks.
Add a checkbox named privacy between the form tag. <input type="checkbox" name="privacy" /> Folowing your script, add validaiton for the checkbox. Just check if the checkbox is selected.