This is the problem:
I have #producto_1
, #producto_2
and #producto_3
, each one has inputs
to fill in automatically.
The way to calculate the net is: bruto*merma/100
, as I have to add more #producto_n
I want it to work more than 1 or 2 times calling the function from: onchange="calculaNeto()
If there is a better method, I am not closed to progress, thanks in advance
function calculaNeto() {
var bruto = $(this).parent().next().find("input").val();
var mermas = $(this).val();
var merma = 100-mermas;
var neto = bruto*(merma/100);
$(this).parents().next().find("input").val(neto);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="producto_1" class="row">
<div id="colusku_1" class="col-sm-2">
<label>Peso bruto</label>
<input type='number' class='form-control' name='bruto1' id='colsku_1' required>
</div>
<div id="colucant_1" class="col-sm-1">
<label>% Merma</label>
<input type='number' class='form-control' name='perdida1' id='colcant_1' onchange="calculaNeto()" required>
</div>
<div id="colucost_1" class="col-sm-2">
<label>Peso Neto <sup>auto</sup> </label>
<input type='number' class='form-control' name='neto1' id='colcost_1' required>
</div>
</div>
<div id="producto_2" class="row">
<div id="colusku_2" class="col-sm-2">
<label>Peso bruto</label>
<input type='number' class='form-control' name='bruto1' id='colsku_2' required>
</div>
<div id="colucant_2" class="col-sm-1">
<label>% Merma</label>
<input type='number' class='form-control' name='perdida2' id='colcant_2' onchange="calculaNeto()" required>
</div>
<div id="colucost_2" class="col-sm-2">
<label>Peso Neto <sup>auto</sup> </label>
<input type='number' class='form-control' name='neto2' id='colcost_2' required>
</div>
</div>