4
Good Afternoon, I am doing a job, of which I will have several forms with a minimum and maximum number and I want to create a check function and avoid inserting numbers out of the track by the keyboard, my function was this way
$(':input[type="number"]').on('keyup', function(event) {
var id = this.id;
var min = document.getElementById(id).getAttribute('min');
var max = document.getElementById(id).getAttribute('max');
verificaTypeNumber(id, min, max);
});
function verificaTypeNumber(idInput, minValue, maxValue) {
var aux = document.getElementById(idInput).value;
if (aux == null || aux < minValue) {
document.getElementById(idInput).value = minValue;
} else if (aux > maxValue) {
document.getElementById(idInput).value = maxValue;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" id="Teste" min="10" max="999" value="10">
When typing a value below the range (in the example less than "10") the function works and enters within the if()
, however for a value above the range (above 999), it does not work and does not enter within the else if()