JQuery .focus() not work in .blur() event in Firefox

Your conditions are messed up and your message doesn’t match your conditions either.
The following will hide the message on focus if the value of #txtfname is 5 or more characters and show the message on blur if its less than 5 characters.

$("#txtfname").focus(function () {
    if ($("#txtfname").val().length >= 5) {
        $("#fnamemsg").hide();
    }
});

$("#txtfname").blur(function () {
    if ($("#txtfname").val().length < 5) {
        $("#fnamemsg").show();
        $("#fnamemsg").html("Minimum 5 characters"); 
        $("#txtfname").focus();
    }
    else { $("#fnamemsg").hide(); }
});

Leave a Comment