selections not calculating hard to see if variable is set
here is my site http://iadprint.com/products?product=product%201
when you select a drop down for attribute19k the price value changes. but when you select other selections nothing happens. if you look in the source way on the bottom is the js that i put. whats supposed to happen is each time a selection is selected the value is accumulated to the total variable and displayed in the pricing span. but i cant see why it doesn't work. the variables are assigned but no calculations are occurring. can anyone see what i cant see?
thanks
ps here is the js
var woattribute19k_price;
var woattribute2_price;
var woattribute3_price;
var woattribute4_price;
var woattribute5_price;
$(document).ready(functi开发者_如何转开发on() {
$("#attribute19k").change(function()
{
hash = $("#attribute19k").val();
$.get("ajax.php", { id: hash },
function(out)
{
woattribute19k_price = out.price;
displayPrice();
}, "json");
});
$("#attribute2").change(function()
{
hash = $("#attribute2").val();
$.get("ajax.php", { id: hash },
function(out)
{
woattribute2_price = out.price;
displayPrice();
}, "json");
});
$("#attribute3").change(function()
{
hash = $("#attribute3").val();
$.get("ajax.php", { id: hash },
function(out)
{
woattribute3_price = out.price;
displayPrice();
}, "json");
});
$("#attribute4").change(function()
{
hash = $("#attribute4").val();
$.get("ajax.php", { id: hash },
function(out)
{
woattribute4_price = out.price;
displayPrice();
}, "json");
});
$("#attribute5").change(function()
{
hash = $("#attribute5").val();
$.get("ajax.php", { id: hash },
function(out)
{
woattribute5_price = out.price;
displayPrice();
}, "json");
});
});
function displayPrice()
{
var total = 0;
var qattribute19k = parseFloat((woattribute19k_price != null) ? woattribute19k_price : 0);
total = parseFloat(total + qattribute19k).toFixed(2);
var qattribute2 = parseFloat((woattribute2_price != null) ? woattribute2_price : 0);
total = parseFloat(total + qattribute2).toFixed(2);
var qattribute3 = parseFloat((woattribute3_price != null) ? woattribute3_price : 0);
total = parseFloat(total + qattribute3).toFixed(2);
var qattribute4 = parseFloat((woattribute4_price != null) ? woattribute4_price : 0);
total = parseFloat(total + qattribute4).toFixed(2);
var qattribute5 = parseFloat((woattribute5_price != null) ? woattribute5_price : 0);
total = parseFloat(total + qattribute5).toFixed(2);
$("#pricing span").text('$' + total);
}
You have to use toFixed only at the end of displayPrice
精彩评论