So I have an issue where I need to make my code when the mouse leaves an input field and the input field is either empty or has less than 5 characters it outputs something
I have tried putting .value after the getelementbyid. Please know that I can't use a button to submit the form.
var username = document.getElementById('username');
var user_length = username.length;
username.onmouseout = function(){
if(username == ""){
alert('hi');
// var username_value =
//document.getElementById("username_output");
// username_value.innerHTML ="Please fill in your username!";
// username_value.style.color = 'red';
}
else if(user_length < 5){
alert('smaller than 5');
}
else{
alert('else');
}
};
Whenever the mouse leaves it should output something. For some reason it's only going in the else statement not the other statements