ksp
07-27-2003, 03:59 PM
Hi,
I'm just not any good at javascript, but I'm desperate to get a form up and running by tomorrow morning. As it is, because I can't get the totals to work with an array, I'm doing it the long way.
There are several categories (each need to be subtotaled then all totaled at the end taking into consideration varying tax and shipping rates).
This is the function I'm trying to use to subtotal the Retail and Wholesale Price fields. When I click the UPDATE button, nothing happens.
What am I doing wrong in my calcSubFood() function?
// Calculate the subtotals for the Food Categories
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);
}
The HTML is basically this:
<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" id="rPrice2" size="10" readonly="readonly"></td>
<td><input name="wPrice2" type="text" id="wPrice2" 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"></td>
<td><input name="wSubFood" type="text" size="10"></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="rSubFood" type="text" size="10" onFocus="subRetailFood();"></td>
<td><input name="wSubFood" 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>
Any help is very much appreciated...
I'm just not any good at javascript, but I'm desperate to get a form up and running by tomorrow morning. As it is, because I can't get the totals to work with an array, I'm doing it the long way.
There are several categories (each need to be subtotaled then all totaled at the end taking into consideration varying tax and shipping rates).
This is the function I'm trying to use to subtotal the Retail and Wholesale Price fields. When I click the UPDATE button, nothing happens.
What am I doing wrong in my calcSubFood() function?
// Calculate the subtotals for the Food Categories
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);
}
The HTML is basically this:
<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" id="rPrice2" size="10" readonly="readonly"></td>
<td><input name="wPrice2" type="text" id="wPrice2" 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"></td>
<td><input name="wSubFood" type="text" size="10"></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="rSubFood" type="text" size="10" onFocus="subRetailFood();"></td>
<td><input name="wSubFood" 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>
Any help is very much appreciated...