input check focusin focusout
as I type in the input field something the jquery part works as I do not understand, please have a look, I need help with it, thank you
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<style>
.warning {
color:red;
}
.ok {
color:green;
}
.inputstatus{
position:static;
background:white;
}
.feedback{
float:right;
right:4px;
}
.star{
float:left;
left:6px;
}
.fielderror{
position:relative;
left:12px;
}
</style>
<script>
$(document).ready(function(){
// $("p").on("click", function(){
// alert("The paragraph was clicked.");
$(".form-control").on( "focusin .box input", function( ){
console.log('changed');
var vr = $(this).attr('name');
var inp =$(this).val().trim()
if ( inp == "" ){
// alert(vr + ' can not be left blank');
$(this).next().find(".fielderror").html(vr + " is empty focusin empty");
$(this).next().css("color", "red");
$(this).css("background-color", "pink");
$(this).next().find(".feedback").removeClass("glyphicon glyphicon-ok ok").addClass("glyphicon glyphicon-remove warning");
event.preventDefault();
}
else {
$(this).next().find(".fielderror").html(vr + " is ok focusin " + inp);
$(this).next().css("color", "green");
$(this).css("background-color", "lightgreen");
$(this).next().find(".feedback").removeClass("glyphicon glyphicon-remove warning").addClass("glyphicon glyphicon-ok ok");
}
});
$(".form-control").on( "focusout .box input", function( ){
console.log('changed');
var vr = $(this).attr('name');
var inp =$(this).val().trim()
if ( inp == "" ){
//alert(vr + ' can not be left blank');
$(this).next().find(".fielderror").html(" Your " + vr + " focusout empty ");
$(this).css("background-color", "white");
$(this).next().find(".feedback").removeClass("glyphicon glyphicon-remove warning").removeClass("glyphicon glyphicon-ok ok");
$(this).next().css("color", "gray");
event.preventDefault();
}
else {
$(this).next().find(".fielderror").html(vr + " is ok focusout " + inp);
$(this).next().css("color", "green");
$(this).css("background-color", "lightgreen");
} $(this).next().find(".feedback").removeClass("glyphicon glyphicon-remove warning").addClass("glyphicon glyphicon-ok ok");
});
});
</script>
</head>
<body>
<p>Click this paragraph.</p>
<h2>Vertical (basic) form</h2>
<form >
<div class="form-group">
<div class="box">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="E-mail">
<div class="inputstatus">
<span class="glyphicon glyphicon-star star"></span>
<span class="fielderror">Your email</span>
<span class="glyphicon feedback"></span>
</div>
</div>
</div>
<div class="form-group">
<div class="box">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="Password">
<div class="inputstatus">
<span class="glyphicon glyphicon-star star"></span>
<span class="fielderror">Your password</span>
<span class="glyphicon feedback"></span>
</div>
</div>
<div class="checkbox">
<label><input type="checkbox" name="remember"> Remember me</label>
</div>
<button type="submit" class="btn btn-default btn1">Submit</button>
</form>
</body>
</html>