/    Sign up×
Community /Pin to ProfileBookmark

calculating wrong in my order form

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&nbsp; – 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″>&nbsp;</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″>&nbsp;</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″>&nbsp;</td>
<td width=”200″><input type=”text” name=”OtherInfo” size=”30″ tabindex=”1″></td>
</tr>
<tr>
<td width=”340″ align=”right”>&nbsp;</td>
<td width=”10″>&nbsp;</td>
<td width=”200″>&nbsp;</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 &quot;A&quot; 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 &quot;B&quot; 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 &quot;C&quot; 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 &quot;D&quot; 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″>&nbsp;</td>
<td align=”center” width=”100″>&nbsp;</td>
<td align=”right” width=”60″>&nbsp;</td>
<td align=”right” width=”140″>&nbsp;</td>
</tr>
<tr>
<td width=”250″>
<p align=”right”><b>TOTALS:</b></td>
<td align=”center” width=”100″>&nbsp;</td>
<td align=”right” width=”60″>&nbsp;</td>
<td align=”right” width=”140″>
<input type=”text” name=”GrandTotal” size=”15″ tabindex=”99″ onchange=”calculate()”></td>
</tr>
<tr>
<td width=”250″>&nbsp;</td>
<td align=”center” width=”100″>&nbsp;</td>
<td align=”right” width=”60″>&nbsp;</td>
<td align=”right” width=”140″>&nbsp;</td>
</tr>
</table>
<p>&nbsp;</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″>&nbsp;&nbsp;&nbsp;&nbsp;
<input type=”reset” value=”Reset” name=”resetButton” tabindex=”50″></td>
</tr>
</table>
</form>

<p>&nbsp;</p>
<p>If you have questions or difficulties with this order page,<br />
&nbsp;please contact
our Customer Service Department (see our Contacts page.)</p>

</body>

</html>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @ChristieB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...