Click to See Complete Forum and Search --> : JS - Form Validation


Kudose
September 25th, 2005, 07:54 PM
Hello all. I have a bit of JS that is supposed to alert when either or both feilds are NULL or empty. As of right now, it only works if both fields are submitted empty. Any help would be greatly appreciated.

I know the following code probably sucks...I am a PHP programmer working towards javascript...it is going...okay.

Also, I did set this function to return a value to the form tag onSubmit.

TIA!

<script language="JavaScript">
<!--
function checkForm(){
var manuf = document.myform.manu_make.value;
var type = document.myform.manu_type.value;
if((manuf == "") || (manuf == NULL))
var err1 = "Please fill out the manufacturer name.";
if((type == "") || (type == NULL))
var err2 = "Please select the manufacturer type.";
if(err1 !== "" || err2 !== ""){
alert(err1+"\n"+err2);
return false;
}
return true;
}
//-->
</script>

Dr. Script
September 25th, 2005, 09:24 PM
I would define err1 and err 2:var err1 = "";
var err2 = "";Otherwise, if they are not defined, usually you'd have to check them against the null/undefined keywords, not the null/empty string.