I have a .click function, each time is executed it adds a group of three divs in a page.
the first div is a number and is multiplied for the second div that holds a currency value; the result is shown in the third div.
I'm trying to write a .each function to calculate the results separately, but it seems that i can not. I feel that should be simple, but i'm missing something. Can someone help? Thanks
here is the code I wrote so far (i tried many different ways...):
===UPDATE==== I updated my code, i added a counter that add an incremental number to the the classes, but I'm still without solution. The code now is
<ul>
<li>Quantità: <span><input type="text" name="Quantita" value="" class="currency2"></span> (metti due decimali - 0.00)</li>
<li>Valore unitario: <span><input type="text" name="ValoreUnitario" value="" class="valore_unitario2"></span></li>
<li>Valore totale: <span><input type="text" name="ValoreTotale" value="" class="somma2"></span></li>
</ul>
<ul>
<li>Quantità: <span><input type="text" name="Quantita" value="" class="currency3"></span> (metti due decimali - 0.00)</li>
<li>Valore unitario: <span><input type="text" name="ValoreUnitario" value="" class="valore_unitario3"></span></li>
<li>Valore totale: <span><input type="text" name="ValoreTotale" value="" class="somma3"></span></li>
</ul>
<ul>
<li>Quantità: <span><input type="text" name="Quantita" value="" class="currency4"></span> (metti due decimali - 0.00)</li>
<li>Valore unitario: <span><input type="text" name="ValoreUnitario" value="" class="valore_unitario4"></span></li>
<li>Valore totale: <span><input type="text" name="ValoreTotale" value="" class="somma4"></span></li>
</ul>
$(".currency"+ counter , ".valore_unitario" + counter).on("change keyup keydown paste propertychange bind mouseover", function(){
var rate = parseFloat($(".currency" + counter ).val()) || 0;
var box = parseFloat($(".valore_unitario" + counter).val()) || 0;
$(".somma" + counter ).val(parseFloat(rate * box).toFixed(2));
});
});