I have a table with three columns and want to sum all fields of the third column where the second field are the same. All sums should then be written to another existing input field that has the id of the second column. Here is my code so far. Any help to complete is nice.

$("#table tr").each(function() { //iterates through each row in a table

var name = $(this).find("input:eq(1)").val(); //value of second inputfield (namefield)

var amount = $(this).find("input:eq(2)").val();//value of third input field (amountfield)

//code to sum amounts for all rows where inputfield 2 is the same

});

// code where each sum amount is written to an existing sum field in a separate table that has the id of inputfield 2 (the name)