My idea is for my form to go through the inputs of type number and if the total of these is higher than the variable faltan
then disable the inputs that are at zero.
Apparently the function works to a certain extent, but when it comes to disabling inputs it does not ....
let faltan = 5;
let total = 0;
$('input[type=number]').change(function() {
console.log('change');
$('input[type=number]').each(function() {
console.log($(this).val());
total = parseInt(total) + parseInt($(this).val());
});
if (total >= faltan) {
$('input[type=number]').each(function() {
console.log('disable');
if ($(this).val() === 0) {
$(this).prop('disabled', true);
}
});
} else {
$('input[type=number]').prop('disabled', false);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myform">
<input type="number" id="1" value="0"><br>
<input type="number" id="2" value="0"><br>
<input type="number" id="3" value="0"><br>
<input type="number" id="4" value="0"><br>
<input type="number" id="5" value="0"><br>
<input type="number" id="6" value="0"><br>
<input type="number" id="7" value="0"><br>
<input type="number" id="8" value="0"><br>
<input type="number" id="9" value="0"><br>
</form>