2
Where is wrong to generate this error? I believe it is in var preco = $(this).next("input.preco").val();
as it replaces the Number(preco)
for Number(qtde)
works, but I need you to be the Number(preco)
, clear-cut.
$('input').change(function() {
var total = 0;
$('input[type=checkbox]:checked').each(function() {
var qtde = $(this).next("input").val();
var preco = $(this).next("input.preco").val();
total += Number(qtde) * Number(preco);
});
$('#total').val(total);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" name="checkbox[]">
<input type="number" value="1" min="1">
<input type="number" class="preco" value="8">
<br>
<input type="checkbox" name="checkbox[]">
<input type="number" value="1" min="1">
<input type="number" class="preco" value="24">
<br>
<input type="checkbox" name="checkbox[]">
<input type="number" value="1" min="1">
<input type="number" class="preco" value="17">
<br><br>
<span>Total:</span><input type="text" id="total" />
I get it, thank you!
– Afuro Terumi