validation is not working please help me to undetstand .i really can not understand validation thank you
<html>
<body>
<form name="theForm" onSubmit="validateFormOnSubmit(theForm)">
<input type="text" name="from">
<input type="text" name="username">
<input type="submit" value="submit"></form>
<script>
function validateFormOnSubmit(theForm) {
var reason = "";
reason = validateUsername(theForm.username);
reason = validatePassword(theForm.pwd);
reason = validateEmail(theForm.email);
reason = validatePhone(theForm.phone);
reason = validateEmpty(theForm.from);
if (reason != "") {
alert("Some fields need correction:\n" reason);
return false;
}
return true;
}
function validateEmpty(fld) {
var error = "";
if (fld.value.length == 0) {
fld.style.background = 'Yellow';
error = "The required field has not been filled in.\n"
} else {
fld.style.background = 'White';
}
return error;
}
</script>
</body>