Im sure you’ve heard this before and you will hear it again. I am a “cut and paster”. I do understand html, but apparently not enough to know why this form that I have modified is not working. I am useing a form designed for three (3) “widgets” marked A, B, & C. I would like to add D (a fourth) or more. In the code below, I added D, but the calculating is wrong in the totals and will not calculate on the fly for D but only A B & C. Any suggestions? Thanx
<html>
<head>
<meta http-equiv=”Content-Language” content=”en-us”>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>
<title>Acme Widgets – Not an actual form!</title>
<script language=javascript>
<!–//
function dm(amount)
{
string = “” + amount;
dec = string.length – string.indexOf(‘.’);
if (string.indexOf(‘.’) == -1)
return string + ‘.00’;
if (dec == 1)
return string + ’00’;
if (dec == 2)
return string + ‘0’;
if (dec > 3)
return string.substring(0,string.length-dec+3);
return string;
}
function calculate()
{
QtyA = 0; QtyB = 0; QtyC = 0; QtyD = 0;
TotA = 0; TotB = 0; TotC = 0; TotD = 0;
PrcA = 1.25; PrcB = 2.35; PrcC = 3.45; PrcD = 4.55;
if (document.ofrm.qtyA.value > “”)
{ QtyA = document.ofrm.qtyA.value };
document.ofrm.qtyA.value = eval(QtyA);
if (document.ofrm.qtyB.value > “”)
{ QtyB = document.ofrm.qtyB.value };
document.ofrm.qtyB.value = eval(Qty?;
if (document.ofrm.qtyC.value > “”)
{ QtyC = document.ofrm.qtyC.value };
document.ofrm.qtyC.value = eval(QtyC);
if (document.ofrm.qtyD.value > “”)
{ QtyD = document.ofrm.qtyD.value };
document.ofrm.qtyD.value = eval(QtyD);
TotA = QtyA * PrcA;
document.ofrm.totalA.value = dm(eval(TotA));
TotB = QtyB * PrcB;
document.ofrm.totalB.value = dm(eval(Tot?);
TotC = QtyC * PrcC;
document.ofrm.totalC.value = dm(eval(TotC));
TotC = QtyD * PrcD;
document.ofrm.totalD.value = dm(eval(TotD));
Totamt =
eval(TotA) +
eval(Tot? +
eval(TotC) +
eval(TotD) ;
document.ofrm.GrandTotal.value = dm(eval(Totamt));
}
//–>
</script>
</head>
<body bgcolor=”#FFFFCC”>
<h2>This is not an actuall form. Nothing will be processed.</h2>
<h3>Get Your Widgets Here!</h3>
<br />
<p>Please make your selections from the following choices:</p>
<form method=”POST” action=”submitted.html” name=”ofrm”>
<p>Please tell us who you are (<font color=”#FF0000″>red</font> denotes
required information):</p>
<table border=”0″ cellpadding=”0″ width=”550″ id=”table1″>
<tr>
<td width=”340″ align=”right”><font color=”#FF0000″>Name</font></td>
<td width=”10″> </td>
<td width=”200″><input type=”text” name=”Name” size=”30″ tabindex=”1″></td>
</tr>
<tr>
<td width=”340″ align=”right”><font color=”#FF0000″>Email</font>
(Your confirmation will be sent here): </td>
<td width=”10″> </td>
<td width=”200″><input type=”text” name=”Email” size=”30″ tabindex=”1″></td>
</tr>
<tr>
<td width=”340″ align=”right”>Other Contact Info:</td>
<td width=”10″> </td>
<td width=”200″><input type=”text” name=”OtherInfo” size=”30″ tabindex=”1″></td>
</tr>
<tr>
<td width=”340″ align=”right”> </td>
<td width=”10″> </td>
<td width=”200″> </td>
</tr>
</table>
<p>And tell us what you would like:</p>
<table border=”0″ cellpadding=”0″ width=”550″ id=”table2″>
<tr>
<td width=”250″ height=”31″><b>Item Description</b></td>
<td align=”center” width=”100″ height=”31″><b>Quantity</b></td>
<td align=”right” height=”31″ width=”60″><b>Price </b></td>
<td align=”right” height=”31″ width=”140″><b>Total</b></td>
</tr>
<tr>
<td width=”250″>Class "A" Widgets</td>
<td align=”center” width=”100″>
<input type=”text” name=”qtyA” size=”5″ tabindex=”5″ onchange=”calculate()”></td>
<td align=”right” width=”60″>1.25</td>
<td align=”right” width=”140″>
<input type=”text” name=”totalA” size=”12″ tabindex=”99″ onchange=”calculate()”></td>
</tr>
<tr>
<td width=”250″>Class "B" Widgets</td>
<td align=”center” width=”100″>
<input type=”text” name=”qtyB” size=”5″ tabindex=”5″ onchange=”calculate()”></td>
<td align=”right” width=”60″>2.35</td>
<td align=”right” width=”140″>
<input type=”text” name=”totalB” size=”12″ tabindex=”99″ onchange=”calculate()”></td>
</tr>
<tr>
<td width=”250″>Class "C" Widgets</td>
<td align=”center” width=”100″>
<input type=”text” name=”qtyC” size=”5″ tabindex=”5″ onchange=”calculate()”></td>
<td align=”right” width=”60″>3.45</td>
<td align=”right” width=”140″>
<input type=”text” name=”totalC” size=”12″ tabindex=”99″ onchange=”calculate()”></td>
</tr>
<tr>
<td width=”250″>Class "D" Widgets</td>
<td align=”center” width=”100″>
<input type=”text” name=”qtyD” size=”5″ tabindex=”5″ onchange=”calculate()”></td>
<td align=”right” width=”60″>4.55</td>
<td align=”right” width=”140″>
<input type=”text” name=”totalD” size=”12″ tabindex=”99″ onchange=”calculate()”></td>
</tr>
<tr>
<td width=”250″> </td>
<td align=”center” width=”100″> </td>
<td align=”right” width=”60″> </td>
<td align=”right” width=”140″> </td>
</tr>
<tr>
<td width=”250″>
<p align=”right”><b>TOTALS:</b></td>
<td align=”center” width=”100″> </td>
<td align=”right” width=”60″> </td>
<td align=”right” width=”140″>
<input type=”text” name=”GrandTotal” size=”15″ tabindex=”99″ onchange=”calculate()”></td>
</tr>
<tr>
<td width=”250″> </td>
<td align=”center” width=”100″> </td>
<td align=”right” width=”60″> </td>
<td align=”right” width=”140″> </td>
</tr>
</table>
<p> </p>
<table border=”0″ cellpadding=”0″ width=”550″ id=”table3″>
<tr>
<td width=”563″>
<p align=”center”>
<input type=”submit” value=”Submit” name=”subButton” tabindex=”50″>
<input type=”reset” value=”Reset” name=”resetButton” tabindex=”50″></td>
</tr>
</table>
</form>
<p> </p>
<p>If you have questions or difficulties with this order page,<br />
please contact
our Customer Service Department (see our Contacts page.)</p>
</body>
</html>