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?
Change this:
cLitreKgValue.replace(/,/g, '.')
to
("" + cLitreKgValue).replace(/,/g, '.')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With