Monday, December 28, 2009

[jQuery] Column total

Column Total

I am using this bit of code to add the values in a table column which
works pretty well until it encounters a null td cell with a  
value. From that point on in the loop, I receive a NaN error in my
alert. I'm wondering how to ignore these non-numeric values or
replace them with zero for the calculation? Thanks


jQuery(function() {
var MarketCapTotal = 0;
// loop through the table
jQuery('#grdWatchlistname tbody tr').each(function() {
// replace the dollar signs and commas
var MarketCap = (jQuery('td:nth-child(4)', jQuery(this)).html
().replace('$', '').replace(/[^a-zA-Z 0-9]+/g, ''));
var td4th = jQuery('td:nth-child(4)', jQuery(this));
MarketCapTotal += parseInt(MarketCap);
alert(MarketCapTotal);
});
});

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate