I am doing a login form ,where, if the input fields is empty I want to declare an error message. I am only getting the 'if' part of the code but not the 'else if' part.
var a = document.getElementById('fname');
var b = document.getElementById('pwd');
var c = document.getElementById('demo1');
var d = document.getElementById('demo2');
function func() {
if (a.value == null || a.value == "") {
c.innerHTML = 'Fields can\'t be empty';
a.style.border = "2px solid red";
return false;
} else if (b.value == null || b.value == "") {
d.innerHTML = "Password should be minimum 6 character";
b.style.border = "2px solid red";
return false;
} else {
true
}
}
input {
display: block;
}
<form action="" onsubmit="return func()">
<input type="text" name="fname" id="fname" placeholder="first name"><br><br>
<p id="demo1" style="color: red;"></p>
<input type="password" name="pwd" id='pwd' placeholder='password'><br><br>
<p id="demo2" style="color: red;"></p>
<button type="submit" id="smbt"> sumbit</button>
</form>