I have some javascript that calculates a price and updates a div. However in ie7 the div calc_sprice displays €NaN.
I think it occurred when I put price formatting in. But I cant see the issue. It works on all other browser though.
function formatPrice (price) {
var dplaces = price == parseInt(price, 10) ? 0 : 2;
price = price.toFixed(dplaces);
return price
}
function calc_supp(showdiv){
var sup = $(showdiv+' .rate_data').attr('sup');
var asup = $(showdiv+' .rate_data').attr('asup');
var csup = $(showdiv+' .rate_data').attr('csup');
//var total_price = $(showdiv+' #total_price').val();
var total_price = $(showdiv+' #tmp_price').val();
total_price = Number(total_price);
var tot_adults = 0;
var tot_childs = 0;
var rooms = 0;
$(showdiv + ' select.adu').each(function(){
var tot_as = $(this).val();
tot_adults += Number(tot_as);
rooms +=1;
});
$(showdiv + ' select.chi').each(function(){
var tot_cs = $(this).val();
tot_childs += Number(tot_cs);
});
var supp = rooms*sup; // total supplement
var total_asupp = Number(tot_adults * asup);
var total_csupp = Number(tot_childs * csup);
var total_sup = Number(supp + total_asupp + total_csupp);
var total_total = Number(total_sup + total_price);
//alert(supp);
$(showdiv + ' .calc_supp span').html(formatPrice(total_sup));
$(showdiv + ' .calc_sprice span').html(formatPrice(total_total));
$(showdiv+' #total_price').val(formatPrice(total_total));
}
Id was being used instead of class. All other browser had no problem with this so didn’t spot it until I tested in ie7