Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Jquery:Sum values of checkbox on same row to textfield on same row
- var total_array = new Array();
- var total_amount = 0;
- $("#dailyexpense input[type=checkbox]:checked ").live('change', function() {
- var check_id = $(this).attr('id');
- var valu = $(this).val();
- $("#tdtotals input[type=text]").each(function() {
- totals_id = $(this).attr('id');
- if (totals_id == check_id) {
- total_array.push(valu);
- total_amount = eval(total_array.join('+')).toFixed(2);
- $(this).val(total_amount);
- }
- });
- });
- //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);
- });
Add Comment
Please, Sign In to add comment