asked on February 19, 2016
I ve got
- a table (q4) of product with a price (q8) at the end of each line.
- A subtotal field (q11) wich is the sum of the price column.
If I add or update a row everyting works great but if I remove a line I need to update my sum. and it doesn't work.
$('#q4').on('click','.form-del-field',updateTotal);
here's my full js :
$(function(){ function round(val){ return Math.round(val * 100) / 100; } function updateTotal () { var sum = 0; $('[id^=Field8\\(]').each(function(){ var val = $(this).val() === '' ? 0 : parseFloat($(this).val()); sum += val; }); $('#Field11').val(round(sum)); } function deleteLine(){ alert('DELETE'); } $(document).on('change', '[id^=Field7\\(]', function(){ var index = $('[id^=Field7\\(]').index($(this)); if ($('[id^=Field6\\(]').eq(index).val() === '' || isNaN($('[id^=Field6\\(]').eq(index).val())) return; $('[id^=Field8\\(]').eq(index).val(round($(this).val() * $('[id^=Field6\\(]').eq(index).val())); updateTotal(); }); $(document).on('change', '[id^=Field6\\(]', function(){ var index = $('[id^=Field6\\(]').index($(this)); if ($('[id^=Field7\\(]').eq(index).val() === '' || isNaN($('[id^=Field7\\(]').eq(index).val())) return; $('[id^=Field8\\(]').eq(index).val(round($(this).val() * $('[id^=Field7\\(]').eq(index).val())); updateTotal(); }); $(document).on('keyup', '[id^=Field6\\(], [id^=Field8\\(]', function(){ if ($(this).val().indexOf('-') !== -1) $(this).val($(this).val().replace(/-/g, '')); }); $(document).on('change', '[id^=Field8\\(]', updateTotal); $('#q4').on('click','.form-del-field',updateTotal); //$('#Field8').attr('readonly', 'readonly'); })
Thanks for your help.
0
0