Всем привет!
когда меняем значение input (не обновляя) хранится самое первое набитое значение.
error.jpg
(выходить "16" а не "77")
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
.errorstyle
{
border: 1px solid #ff0000;
background: #fff3f3;
}
.popover
{
box-shadow: 5px 0px 40px rgba(0,0,0, .2);
max-width: 500px !important;
max-height: 200px !important;
overflow-y: auto;
overflow-x: hidden;
border: 1px solid #ff0000;
background: #fff3f3;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script>
$(function(){
$('.container').on('focusout', '#second', function () {
let first = $('#first').val().trim();
let second = $('#second').val().trim();
if (second)
if (+first <= +second) {
let errortext = '<p>The value of first (' + first +') input must be greater than the value of secondone (' + second + ')</p>';
let poperror = {
content: errortext,
html: true,
trigger: 'focus',
placement: 'bottom'
};
$('#second').popover(poperror).popover('enable');
$('#second').addClass("errorstyle");
} else {
$('#second').popover('disable');
$('#second').removeClass("errorstyle");
}
});
});
</script>
</head>
<body>
<div class="container">
<form>
<div class="form-group">
<label for="first">First:</label>
<input type="number" class="form-control" id="first" name="firstone">
</div>
<div class="form-group">
<label for="second">Second:</label>
<input type="number" class="form-control" id="second" name="secondone">
</div>
</form>
</div>
</body>
</html>