ksp
07-27-2003, 06:14 PM
Hi,
I'm trying to get the subtotals of Retail Prices and Wholesale prices. I've got some bugs worked out now (compared to earlier post), but now the result of clicking on the UPDATE button is $na in both subtotal fields.
Does that have to do with converting strings or something, and if so (or if not), what do I need to do to fix that?
Thanks for any assistance.
<!-- 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 to calculate subtotal of Food Products Category items 1 thru 3
function calcSubFood() {
var f = window.document.mProducts; // f for form
var rFoodSubtotal = (f.rPrice1.value + f.rPrice2.value + f.rPrice3.value);
var wFoodSubtotal = (f.wPrice1.value + f.wPrice2.value + f.wPrice3.value);
f.rSubFood.value = "$" + round(rFoodSubtotal);
f.wSubFood.value = "$" + round(wFoodSubtotal);
}
// End hiding -->
HTML:
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Original Price Format</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="javascript" src="basecalc4.js"></script>
</head>
<style type="text/css">
body {
text-align: center;
margin-top: 40px;
background: ghostwhite;
}
table {
width: 600px;
border-collapse: collapse;
border: 4px black double;
}
th {
font: 600 12px helvetica, sans-serif;
margin: 1px;
padding: 1px;
border: 1px black solid;
background: #f4ccc0;
}
th.category {
font: 600 13px helvetica, sans-serif;
color: white;
margin: 1px;
padding: 2px;
border: 2px black solid;
background: #993333;
}
td {
font: 200 11px helvetica, sans-serif;
text-align: center;
margin: 2px;
padding: 2px;
border: 3px black double;
background: #f8eef0;
}
td.total {
background: #efb0b0;
}
td#grtotal {
background: #ffe0d0;
}
input {
font: 200 11px helvetica, sans-serif;
}
</style>
<body>
<form name="mProducts" action="" method="">
<table width="100%" cellpadding="1" class="wsproducts">
<tr>
<th colspan="8">FOOD PRODUCTS</th>
</tr>
<tr>
<th width="4%">Qty</th>
<th width="8%">Stock No.</th>
<th width="25%">Product</th>
<th width="12%">Retail</th>
<th width="11%">Wholesale</th>
<th width="12%">Total Retail</th>
<th width="12%"><p>Total<br>
Wholesale</p></th>
<th width="16%"> </th>
</tr>
<tr>
<td><input name="qty1" type="text" size="3" onblur="determineRWPrices(this)"></td>
<td><input type="hidden" name="stock" value="100">
100</td>
<td><input type="hidden" name="product" value="Beer Bread">
Old World Beer Bread</td>
<td><input type="hidden" name="drPrice1" value="4.99">
$4.99</td>
<td><input type="hidden" name="dwPrice1" value="3.24">
$3.24</td>
<td><input name="rPrice1" type="text" size="10" readonly="readonly"></td>
<td><input name="wPrice1" type="text" size="10" readonly="readonly"></td>
<td> </td>
</tr>
<tr>
<td><input name="qty2" type="text" id="qty2" size="3" onblur="determineRWPrices(this)"></td>
<td><input type="hidden" name="stock" value="101">
101</td>
<td><input type="hidden" name="product" value="Cranberry Muffins">
Cranberry Orange Muffins</td>
<td><input type="hidden" name="drPrice2" value="5.99">
$5.99</td>
<td><input type="hidden" name="dwPrice2" value="3.89">
$3.89</td>
<td><input name="rPrice2" type="text" size="10" readonly="readonly"></td>
<td><input name="wPrice2" type="text" size="10" readonly="readonly"></td>
<td> </td>
</tr>
<tr>
<td><input name="qty3" type="text" size="3" onblur="determineRWPrices(this)"></td>
<td><input type="hidden" name="stock" value="110">
110</td>
<td><input type="hidden" name="product" value="BBQ Dip">
BBQ & Dipping Sauce</td>
<td><input type="hidden" name="drPrice3" value="5.99">
$5.99</td>
<td><input type="hidden" name="dwPrice3" value="3.89">
$3.89</td>
<td><input name="rPrice3" type="text" size="10" readonly="readonly"></td>
<td><input name="wPrice3" type="text" size="10" readonly="readonly"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"><div align="right"><strong>Subtotal Food Items:</strong></div></td>
<td><input name="rSubFood" type="text" size="10" readonly="readonly"></td>
<td><input name="wSubFood" type="text" size="10" readonly="readonly"></td>
<td><input type="button" value="UPDATE" onclick="calcSubFood(); return false;" name="button"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"><div align="right"><strong>Enter Your State's Non-Food Tax
Rate, <br />
If Applicable:</strong></div></td>
<td><input type="text" name="nonfood_tax" size="10"></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"><div align="right"><strong>Total Food Products: </strong></div></td>
<td><input name="rTotalFood" type="text" size="10"></td>
<td><input name="wTotalFood" type="text" size="10"></td>
<td><input type="button" value="UPDATE" onClick="calcTotalFood(); return false;" name="button"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="5"> </td>
<td> </td>
</tr>
</table>
</form></td>
</body>
</html>
I'm trying to get the subtotals of Retail Prices and Wholesale prices. I've got some bugs worked out now (compared to earlier post), but now the result of clicking on the UPDATE button is $na in both subtotal fields.
Does that have to do with converting strings or something, and if so (or if not), what do I need to do to fix that?
Thanks for any assistance.
<!-- 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 to calculate subtotal of Food Products Category items 1 thru 3
function calcSubFood() {
var f = window.document.mProducts; // f for form
var rFoodSubtotal = (f.rPrice1.value + f.rPrice2.value + f.rPrice3.value);
var wFoodSubtotal = (f.wPrice1.value + f.wPrice2.value + f.wPrice3.value);
f.rSubFood.value = "$" + round(rFoodSubtotal);
f.wSubFood.value = "$" + round(wFoodSubtotal);
}
// End hiding -->
HTML:
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Original Price Format</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="javascript" src="basecalc4.js"></script>
</head>
<style type="text/css">
body {
text-align: center;
margin-top: 40px;
background: ghostwhite;
}
table {
width: 600px;
border-collapse: collapse;
border: 4px black double;
}
th {
font: 600 12px helvetica, sans-serif;
margin: 1px;
padding: 1px;
border: 1px black solid;
background: #f4ccc0;
}
th.category {
font: 600 13px helvetica, sans-serif;
color: white;
margin: 1px;
padding: 2px;
border: 2px black solid;
background: #993333;
}
td {
font: 200 11px helvetica, sans-serif;
text-align: center;
margin: 2px;
padding: 2px;
border: 3px black double;
background: #f8eef0;
}
td.total {
background: #efb0b0;
}
td#grtotal {
background: #ffe0d0;
}
input {
font: 200 11px helvetica, sans-serif;
}
</style>
<body>
<form name="mProducts" action="" method="">
<table width="100%" cellpadding="1" class="wsproducts">
<tr>
<th colspan="8">FOOD PRODUCTS</th>
</tr>
<tr>
<th width="4%">Qty</th>
<th width="8%">Stock No.</th>
<th width="25%">Product</th>
<th width="12%">Retail</th>
<th width="11%">Wholesale</th>
<th width="12%">Total Retail</th>
<th width="12%"><p>Total<br>
Wholesale</p></th>
<th width="16%"> </th>
</tr>
<tr>
<td><input name="qty1" type="text" size="3" onblur="determineRWPrices(this)"></td>
<td><input type="hidden" name="stock" value="100">
100</td>
<td><input type="hidden" name="product" value="Beer Bread">
Old World Beer Bread</td>
<td><input type="hidden" name="drPrice1" value="4.99">
$4.99</td>
<td><input type="hidden" name="dwPrice1" value="3.24">
$3.24</td>
<td><input name="rPrice1" type="text" size="10" readonly="readonly"></td>
<td><input name="wPrice1" type="text" size="10" readonly="readonly"></td>
<td> </td>
</tr>
<tr>
<td><input name="qty2" type="text" id="qty2" size="3" onblur="determineRWPrices(this)"></td>
<td><input type="hidden" name="stock" value="101">
101</td>
<td><input type="hidden" name="product" value="Cranberry Muffins">
Cranberry Orange Muffins</td>
<td><input type="hidden" name="drPrice2" value="5.99">
$5.99</td>
<td><input type="hidden" name="dwPrice2" value="3.89">
$3.89</td>
<td><input name="rPrice2" type="text" size="10" readonly="readonly"></td>
<td><input name="wPrice2" type="text" size="10" readonly="readonly"></td>
<td> </td>
</tr>
<tr>
<td><input name="qty3" type="text" size="3" onblur="determineRWPrices(this)"></td>
<td><input type="hidden" name="stock" value="110">
110</td>
<td><input type="hidden" name="product" value="BBQ Dip">
BBQ & Dipping Sauce</td>
<td><input type="hidden" name="drPrice3" value="5.99">
$5.99</td>
<td><input type="hidden" name="dwPrice3" value="3.89">
$3.89</td>
<td><input name="rPrice3" type="text" size="10" readonly="readonly"></td>
<td><input name="wPrice3" type="text" size="10" readonly="readonly"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"><div align="right"><strong>Subtotal Food Items:</strong></div></td>
<td><input name="rSubFood" type="text" size="10" readonly="readonly"></td>
<td><input name="wSubFood" type="text" size="10" readonly="readonly"></td>
<td><input type="button" value="UPDATE" onclick="calcSubFood(); return false;" name="button"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"><div align="right"><strong>Enter Your State's Non-Food Tax
Rate, <br />
If Applicable:</strong></div></td>
<td><input type="text" name="nonfood_tax" size="10"></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"><div align="right"><strong>Total Food Products: </strong></div></td>
<td><input name="rTotalFood" type="text" size="10"></td>
<td><input name="wTotalFood" type="text" size="10"></td>
<td><input type="button" value="UPDATE" onClick="calcTotalFood(); return false;" name="button"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="5"> </td>
<td> </td>
</tr>
</table>
</form></td>
</body>
</html>