Add values of previous rows for column jquery -
i trying add values of previous rows in column click using jquery. @ moment have following code :
$( document ).ready(function() { $('td').click(function() { var col = $(this).parent().children().index($(this)); var row = $(this).parent().parent().children().index($(this).parent()); console.log('row: ' + row + ', column: ' + col); var val1=0; var val2=0; var t = document.getelementbyid('hours'); (i = 1; < row; i++) { var val1=$(t.rows[i].cells[col]).text(); console.log('row: ' + + ', column: ' + col); console.log($('#hours tr:eq('+i+') td:eq('+col+')').text); val2 += number(val1); } });
});
i've got right column having trouble pulling values. table id : hours
replace
for (i = 1; < row; i++)
with
for( = 0 ; i<row ; i++)
because otherwise ignores first row
i suggest loop code
var val1 = 0 try { var txtval1 = t.rows[i].cells[col].textcontent; val1 = parsefloat(txtval1); if (isnan(val1)) val1 = 0.0; // or use parseint , remove isnan test val2 += val1; } catch(e){ console.log("row:" + +', col: '+col+'can not parse: '+ txtval1); }
Comments
Post a Comment