Skip to content Skip to sidebar Skip to footer

Jquery:sum Values Of Checkbox On Same Row To Textfield On Same Row

I have some checkboxes with values which need sum up. When the checkboxes are checked the values get added in an array and displayed. Here is a demo link: http://jsfiddle.net/maxwe

Solution 1:

Try this:

http://jsfiddle.net/gKWmB/3/

Basically we rethink the structure. If a checkbox value changes we get its parent row. Then we find all checkboxes in that row. Finally we total them and display.

//watch checkboxes
$('tr input[type=checkbox]').change( function(){   
  var total = 0;
  //total all sibling checkboxes
  $(this).parents('tr').find('input[type=checkbox]:checked').each( function() {
    total += parseInt($(this).val());        
  });

  //display the result
  $(this).parents('tr').find('input[type=text]:last').val(total);
});

Post a Comment for "Jquery:sum Values Of Checkbox On Same Row To Textfield On Same Row"