ksp
07-28-2003, 08:07 AM
Hi again,
After getting similar help here to take care of $Na in the subtotal fields, I'm finding I now have trouble in the tax field where the total of the Wholesale price is based on the input of the tax amount (the retail total is okay, but no tax is figured into it).
I tried to use the same code (logic) in order not to get $Na again (the val(str) function), but I still get $Na in the Wholesale total. I'm assuming it has something to do with the way I've entered the tax variable.
Can someone please help me again...
I've got a sample posted here:
http://www.tnni.net/~kathy/test/test.html
I just tried it again, and the $Na appears if there's no value entered in the tax (in that case it should just be the same amount as the subtotal); and when there is an amount entered, it gives an inaccurate total... why?
Also, how would I make certain that someone entered the tax value in the proper format (for example, .06 (or whatever) instead of 6%)? An alert box or is there a better way? Thanks...
<!-- Hide
// Function to round to two decimal places
function round (n, d) {
n = n - 0;
d = d || 2;
var f = Math.pow(10, d);
n = Math.round(n * f) / f;
n += Math.pow(10, - (d + 1));
n += '';
return d == 0 ? n.substring(0, n.indexOf('.')) :
n.substring(0, n.indexOf('.') + d + 1);
}
// Determine line by line retail and wholesale prices for each product after quantity ordered
function determineRWPrices(){
var f = window.document.mProducts; // f for form
// r Price is total Retail Price
// w Price is total Wholesale Price
var qty1 = f.qty1.value; // Quantity of items ordered
f.rPrice1.value = "$" + round(f.drPrice1.value * qty1); // Default retail price times quantity
f.wPrice1.value = "$" + round(f.dwPrice1.value * qty1); // Default wholesale price times quantity
var qty2 = f.qty2.value;
f.rPrice2.value = "$" + round(f.drPrice2.value * qty2);
f.wPrice2.value = "$" + round(f.dwPrice2.value * qty2);
var qty3 = f.qty3.value;
f.rPrice3.value = "$" + round(f.drPrice3.value * qty3);
f.wPrice3.value = "$" + round(f.dwPrice3.value * qty3);
}
function val(str) {
return parseFloat(str.substr(1))
}
// Function to calculate subtotal of Food Products Category items 1 thru 3
function calcSubFood() {
var f = window.document.mProducts; // f for form
var rFoodSubtotal = parseFloat(f.rPrice1.value + f.rPrice2.value + f.rPrice3.value);
var wFoodSubtotal = parseFloat(f.wPrice1.value + f.wPrice2.value + f.wPrice3.value);
var rFoodSubtotal = (val(f.rPrice1.value) + val(f.rPrice2.value) + val(f.rPrice3.value));
var wFoodSubtotal = (val(f.wPrice1.value) + val(f.wPrice2.value) + val(f.wPrice3.value));
f.rSubFood.value = "$" + round(rFoodSubtotal);
f.wSubFood.value = "$" + round(wFoodSubtotal);
}
function calcTotalFood() {
var f = window.document.mProducts; // f for form
var rFoodTotal = parseFloat(f.rSubFood.value);
var wFoodTotal = parseFloat(f.wSubFood.value * f.foodtax.value);
var rFoodTotal = (val(f.rSubFood.value));
var wFoodTotal = (val(f.wSubFood.value) * val(f.foodtax.value));
f.rTotalFood.value = "$" + round(rFoodTotal);
f.wTotalFood.value = "$" + round(wFoodTotal);
}
// End hiding -->
Thank you.
After getting similar help here to take care of $Na in the subtotal fields, I'm finding I now have trouble in the tax field where the total of the Wholesale price is based on the input of the tax amount (the retail total is okay, but no tax is figured into it).
I tried to use the same code (logic) in order not to get $Na again (the val(str) function), but I still get $Na in the Wholesale total. I'm assuming it has something to do with the way I've entered the tax variable.
Can someone please help me again...
I've got a sample posted here:
http://www.tnni.net/~kathy/test/test.html
I just tried it again, and the $Na appears if there's no value entered in the tax (in that case it should just be the same amount as the subtotal); and when there is an amount entered, it gives an inaccurate total... why?
Also, how would I make certain that someone entered the tax value in the proper format (for example, .06 (or whatever) instead of 6%)? An alert box or is there a better way? Thanks...
<!-- Hide
// Function to round to two decimal places
function round (n, d) {
n = n - 0;
d = d || 2;
var f = Math.pow(10, d);
n = Math.round(n * f) / f;
n += Math.pow(10, - (d + 1));
n += '';
return d == 0 ? n.substring(0, n.indexOf('.')) :
n.substring(0, n.indexOf('.') + d + 1);
}
// Determine line by line retail and wholesale prices for each product after quantity ordered
function determineRWPrices(){
var f = window.document.mProducts; // f for form
// r Price is total Retail Price
// w Price is total Wholesale Price
var qty1 = f.qty1.value; // Quantity of items ordered
f.rPrice1.value = "$" + round(f.drPrice1.value * qty1); // Default retail price times quantity
f.wPrice1.value = "$" + round(f.dwPrice1.value * qty1); // Default wholesale price times quantity
var qty2 = f.qty2.value;
f.rPrice2.value = "$" + round(f.drPrice2.value * qty2);
f.wPrice2.value = "$" + round(f.dwPrice2.value * qty2);
var qty3 = f.qty3.value;
f.rPrice3.value = "$" + round(f.drPrice3.value * qty3);
f.wPrice3.value = "$" + round(f.dwPrice3.value * qty3);
}
function val(str) {
return parseFloat(str.substr(1))
}
// Function to calculate subtotal of Food Products Category items 1 thru 3
function calcSubFood() {
var f = window.document.mProducts; // f for form
var rFoodSubtotal = parseFloat(f.rPrice1.value + f.rPrice2.value + f.rPrice3.value);
var wFoodSubtotal = parseFloat(f.wPrice1.value + f.wPrice2.value + f.wPrice3.value);
var rFoodSubtotal = (val(f.rPrice1.value) + val(f.rPrice2.value) + val(f.rPrice3.value));
var wFoodSubtotal = (val(f.wPrice1.value) + val(f.wPrice2.value) + val(f.wPrice3.value));
f.rSubFood.value = "$" + round(rFoodSubtotal);
f.wSubFood.value = "$" + round(wFoodSubtotal);
}
function calcTotalFood() {
var f = window.document.mProducts; // f for form
var rFoodTotal = parseFloat(f.rSubFood.value);
var wFoodTotal = parseFloat(f.wSubFood.value * f.foodtax.value);
var rFoodTotal = (val(f.rSubFood.value));
var wFoodTotal = (val(f.wSubFood.value) * val(f.foodtax.value));
f.rTotalFood.value = "$" + round(rFoodTotal);
f.wTotalFood.value = "$" + round(wFoodTotal);
}
// End hiding -->
Thank you.