Where's the error in this code?

This is the code that should calculate the totals of a table. It’s linked to an input field for filtering, to which I’ve attached a keyup event in order to recalculate the totals everytime the data in the table is somehow filtered.



$(document).ready(function() {
        $('input[name=ricerca]').keyup(function(){
                $val=$(this).val();
		$('table[id=incontri] tbody tr:not(:contains("' + $val + '"))').hide();
		$('table[id=incontri] tbody tr:contains("' + $val + '")').show();
		calcolaTotali();
	},
	
	function calcolaTotali() {
		var cellObjs = getElementsByClassName(document, 'td', "coppie");
                var sum = 0;
                for(i=0; i < cellObjs.length; i++) {
                	if(cellObjs[i].parent.style.display != 'none' ) {
                    sum += new Number(cellObjs[i].innerHTML);
                  }
                }
                document.getElementById('incontritotali').innerHTML = sum;
	},
	
	function getElementsByClassName(oElm, strTagName, strClassName){
                var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
                var arrReturnElements = new Array();
                strClassName = strClassName.replace(/\\-/g, "\\\\-");
                var oRegExp = new RegExp("(^|\\\\s)" + strClassName + "(\\\\s|$)");
                var oElement;
                for(var i=0; i<arrElements.length; i++){
                    oElement = arrElements[i];
                    if(oRegExp.test(oElement.className)){
                        arrReturnElements.push(oElement);
                    }
                }
                return (arrReturnElements)
	}),
});

The first part of the code is for filtering the table rows based on the input of the user, and this part works, the rows are correctly hidden or shown. The calculation of the totals doesn’t work, I get no output.

I can’t understand where the problem lies. Can you help me?

you must learn how to debug programe by step!
var cellObjs = getElementsByClassName(document, ‘td’, “coppie”);
pls confirm cellObjs val ?

I definitely do :smiley:

Anyway, I’ve rewritten the whole code using jQuery and now it works…