Guest User

Untitled

a guest
Aug 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Jquery:Sum values of checkbox on same row to textfield on same row
  2. var total_array = new Array();
  3. var total_amount = 0;
  4. $("#dailyexpense input[type=checkbox]:checked ").live('change', function() {
  5.  
  6. var check_id = $(this).attr('id');
  7. var valu = $(this).val();
  8. $("#tdtotals input[type=text]").each(function() {
  9. totals_id = $(this).attr('id');
  10. if (totals_id == check_id) {
  11. total_array.push(valu);
  12. total_amount = eval(total_array.join('+')).toFixed(2);
  13. $(this).val(total_amount);
  14. }
  15.  
  16. });
  17. });
  18.  
  19. //watch checkboxes
  20. $('tr input[type=checkbox]').change( function(){
  21. var total = 0;
  22. //total all sibling checkboxes
  23. $(this).parents('tr').find('input[type=checkbox]:checked').each( function() {
  24. total += parseInt($(this).val());
  25. });
  26.  
  27. //display the result
  28. $(this).parents('tr').find('input[type=text]:last').val(total);
  29. });
Add Comment
Please, Sign In to add comment