javascript - Add table column cells with input textbox and without -


i adding values of column in table following javascript function:

function sumofcolumns(tableid, columnindex, hasheader) {     var tot = 0;     $("#" + tableid + " tr" + (hasheader ? ":gt(0)" : ""))     .children("td:nth-child(" + columnindex + ")")     .each(function() {         tot += $(this).html();     });     return tot; } 

i modify adds not numbers in cell, include value of textboxes in cells. cell can either have number or textbox number.

the following cells should add 2115:

<table> <tr><td>100</td></tr> <tr><td><input type="text" value="5" /></td></tr> <tr><td>10</td></tr> <tr><td><input type="text" value="2000" /></td></tr> </table> 

how can efficiently? input!

you this:

function sumofcolumns(tableid, columnindex, hasheader) {     var tot = 0;     $("#" + tableid + " tr" + (hasheader ? ":gt(0)" : ""))     .children("td:nth-child(" + columnindex + ")")     .each(function() {         tot += parsefloat($(this).text() || $('input:text', this).val());     });     return tot; } 

i substituted parsefloat() didn't include fnum(text, bool) function.

demo here: http://jsfiddle.net/jameskovacs/hvbhq/


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -