I am trying to validate a form and want to check whether fields are empty. And if more than one fields are empty it will show error for only the first one of them.
So I was suggested to use nested if else for that. But that is creating an arrow shape code which I don't like.
Any way to make it a function with few lines?
var firstName = document.getElementByI("firstName").value;
var lastName = document.getElementByI("lastName").value;
var email = document.getElementByI("email").value;
if(firstname!=""){
if(lastname!=""){
if(email!=""){
return "";
}
else
{ document.getElementByI("email").focus();
return "email is required";
}
}
else
{
document.getElementByI("lastName").focus();
return "lastname is required";
}
}
else{
document.getElementByI("firstName").focus();
return "firstname is required";
}