<!DOCTYPE html>
<html lang="en">
<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>
<script>
$(document).ready(function(){
$(".form-control").on( "blur input", function( ){
console.log('changed');
var vr = $(this).attr('name');
var inp = $(".form-control").val().trim();
if ( inp === "" ){
alert(vr + ' can not be left blank');
$(this).next().html(vr + " is empty ");
event.preventDefault();
}
else {
$(this).next().html(vr + " is ok ");
}
});
$(".btn1").click(function(){
$( ".form-control" ).each(function() {
var vr = $(this).attr('name');
if ($('input').val().trim() === ""){
alert(vr + ' can not be left blank');
$(this).next().html(vr + " is empty ");
event.preventDefault();
} else {
$(this).next().html(vr + " is ok ");
}
});
});
});
</script>
</head>
<body>
<div class="container">
<h2>Vertical (basic) form</h2>
<form >
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
<span>email</span>
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pwd">
<span>password</span>
</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>
</div>
</body>
</html>