javascript or jQuery? In jQuery use of each function would easily solve it.
function sumRows() {
var totalSum = 0;
$("tr").each(function(item, index) {
totalSum += item.value;
});
}
In javascript, you should select by tag and do for loop accumulating sum of each row. You might need further filtering if your design contains other rows...
Something like:
function sumRows() {
var rows = document.getElementByTagName("tr");
var totalSum = 0;
for (i=0; i<rows.lenght-1;>
totalSum += 1;
}
}
Solution based on your html above - using jQuery. ^= reads as starts with so it selects particular series of input boxes regardless of the identification part.
function sumRows()
{
var particulars = $("input[id^=txtParticulars]");
var sumParticulars = 0;
if (particulars != null)
particulars.each(function(index) {
sumParticulars += this.val();
});
var quantities = $("input[id^=txtQty]");
var sumQuantities = 0;
if (quantities != null){
quantities.each(function(index) {
sumQuantities += this.val();
});
}