Skipjackrick Posted February 22, 2009 Share Posted February 22, 2009 I put a form validation code in the head of my documents but my select options have the value=null for the first value and some have value=0....Therefore, Is it possible to set the "obj.value" to == 0 AND null ? That way it will not let the user continue with a null value also. function formCheck(formobj){ // Enter name of mandatory fields var fieldRequired = Array("angler", "species_id", "mm", "dd"); // Enter field description to appear in the dialog box var fieldDescription = Array("Angler", "Species Name", "Month", "Day"); // dialog message var alertMsg = "Please complete the following fields:\n"; var l_Msg = alertMsg.length; for (var i = 0; i < fieldRequired.length; i++){ var obj = formobj.elements[fieldRequired[i]]; if (obj){ switch(obj.type){ case "select-one": if (obj.value == 0){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "select-multiple": if (obj.selectedIndex == -1){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "text": if (obj.value == ""){ alertMsg += " - " + fieldDescription[i] + "\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[i] + "\n"; } } } } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } Link to comment https://forums.phpfreaks.com/topic/146409-help-with-if-with-two-conditions-on-form-validation/ Share on other sites More sharing options...
darkfreaks Posted February 22, 2009 Share Posted February 22, 2009 if(obj.value=='' AND obj.value=='NULL'){} Link to comment https://forums.phpfreaks.com/topic/146409-help-with-if-with-two-conditions-on-form-validation/#findComment-768707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.