I have a textbox and need to be validated after onblur()
event. There should be error message, if and only if the textbox is empty else no message is displayed on webpage. But I think if
part of the javascript is executing each time.
<input placeholder="First Name" type="text" name="fname" onblur="validatefname()">
Javascript function
function validatefname(){
var fn=document.getElementsByName("fname").value;
if(fn==null || fn==""){
document.getElementById("bubble").style.visibility="visible";
return false;
}
else{
document.getElementById("bubble").style.visibility="hidden";
return true;
}
}
Please let me know what went wrong here?