I'm trying to validate multiple fields in a form. For the most part my code seems to work, but upon further testing I noticed some strange behavior. For whatever reason My form seems to go through if the last field is working, in this case all other error checks are ignored. also on a side note my messages don't seem to update, after a wrong submission, is submitted again with different errors. Can anyone please explain to me why this happens?
here is my submit button.
<button type="submit" onclick="return validateRegistrationForm()" >
Register
</button>
Script:
function validateRegistrationForm()
{
return validateUsername(), validatePassword(), validateConfirmPassword();
}
function validateUsername()
{
var x=document.forms["registration"]["userName"].value;if (x == null || x == "")
{
document.getElementById("usernameWarnings").innerHTML = "Username is Required!";
return false;
}
else if (x.length < 6 || x.lenth > 10)
{
document.getElementById("usernameWarnings").innerHTML = "Must be Between 6 to 10 Characters!";
return false;
}
else
{
return true;
}
}
function validatePassword()
{
var y=document.forms["registration"]["userPassword"].value;
if (y == null || y == "")
{
document.getElementById("passwordWarnings").innerHTML = "Password is Required!";
return false;
}
else if (y.length < 6 || y.lenth > 10)
{
document.getElementById("passwordWarnings").innerHTML = "Must be Between 6 to 10 Characters!";
return false;
}
else
{
return true;
}
}
function validateConfirmPassword()
{
var y=document.forms["registration"]["userPassword"].value;
var k=document.forms["registration"]["cUserPassword"].value;
if (k == null || k == "")
{
document.getElementById("confirmPasswordWarnings").innerHTML = "Confirm Password is Required!";
return false;
}
else if (y != k)
{
document.getElementById("confirmPasswordWarnings").innerHTML = "Passwords not the same";
return false;
}
else
{
return true;
}
}
return validateUsername(), validatePassword(), validateConfirmPassword();