Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  110] [ 6]  / answers: 1 / hits: 85261  / 14 Years ago, tue, june 29, 2010, 12:00:00

I have this function:



function countLitreKgSums(cProductIds){
var cLitreKgSums = new Array();
var cWeek = 0;
for(i=0;i<cProductIds.length;i++){
var cLitreKgSum = 0;
$(#plan_table td[class='week']).each(function(){
cWeek = $(this).html();
var cLitreKgValue = $(input[name*='plan_table_week + cWeek + _prod + cProductIds[i] + _']).val();
if (cLitreKgValue == ) {
cLitreKgValue = 0;
}
cLitreKgValue = cLitreKgValue.replace(/,/g, '.').replace(/[^d.]/g, '').replace(/s/g, '');
cLitreKgValue = parseFloat(cLitreKgValue);
cLitreKgSum += cLitreKgValue;
});
cLitreKgSum = Math.round(cLitreKgSum * 100) / 100;
cLitreKgSums[i] = cLitreKgSum;
}
return cLitreKgSums;
//console.log(cLitreKgSums);
}


I get error message that .replace is not a function but in other functions it works as it should. What is the difference?


More From » jquery

 Answers
14

cLitreKgValue might be a number at the point where you try to call replace on it, not a string. In which case, the error is correct - numbers don't have a replace method.


[#96384] Friday, June 25, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradford

Total Points: 709
Total Questions: 117
Total Answers: 91

Location: Sao Tome and Principe
Member since Wed, Dec 21, 2022
1 Year ago
;