Ask a Question related to Macromedia Dynamic HTML, Design and Development.
-
noobie2005 #1
Totaling textboxes
Hi,
I'm having trouble figureing out the last part of this problem. I'am using a
javascript function to give me a grand total price for all the items in the
boxes (item quantity * item price). What I can't figure out is how to get each
price to display individualy in each seperate box.
I've attatched some code, to hopefully clarify what I'm talking about. Thank
you in advance!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<script language="JavaScript" type="text/javascript">
<!--
function CalculateOrder(frm)
{
var order_total = 0
var item_total = 0
// run through all the form fields
for (var i=0; i < frm.elements.length; ++i)
{
// get current field
form_field = frm.elements[i]
// get field's name
form_name = form_field.name
// "quantity" field?
if (form_name.substring(0,3) == "qty")
{
// get the quantity
item_quantity = form_field.value
}
//"cost" field?
if (form_name.substring(0,4) == "cost")
{
//get price
item_price = form_field.value
if (item_quantity >= 0)
{
order_total += item_quantity * item_price
}
}
if (form_name.substring(0,5) == "total")
{
item_total == item_quantity * item_price
item_total = form_field.value
}
}
// display total
frm.grandtotal.value = order_total
frm.total.value = item_total
}
//-->
</script>
<body>
<form>
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td colspan="2" valign="top"><strong>D.</strong></td>
<td colspan="2" valign="top"><strong>E. Purchases Only</strong></td>
</tr>
<tr>
<td valign="top"><strong>ITEM</strong></td>
<td valign="top"><strong>QTY</strong></td>
<td valign="top"><strong>COST</strong></td>
<td valign="top"><strong>TOTAL</strong></td>
</tr>
<tr>
<td valign="top"><input type="text" size="40" name="item1"></td>
<td valign="top"><input type="text" size="5" name="qty1"></td>
<td valign="top"><input type="text" size="10" name="cost1"
onChange="CalculateOrder(this.form)"></td>
<td valign="top"><input type="text" size="10"
name="total2"onFocus="this.form.total.focus()"></td>
</tr>
<tr>
<td valign="top"><input type="text" size="40" name="item3"></td>
<td valign="top"><input type="text" size="5" name="qty3"></td>
<td valign="top"><input type="text" size="10" name="cost3"
onChange="CalculateOrder(this.form)"></td>
<td valign="top"><input type="text" size="10"
name="total3"onFocus="this.form.total.focus()"></td>
</tr>
<tr>
<td valign="top"><input type="text" size="40" name="item4"></td>
<td valign="top"><input type="text" size="5" name="qty4"></td>
<td valign="top"><input type="text" size="10" name="cost4"
onChange="CalculateOrder(this.form)"></td>
<td valign="top"><input type="text" size="10"
name="total4"onFocus="this.form.total.focus()"></td>
</tr>
<tr>
<td valign="top"><input type="text" size="40" name="item5"></td>
<td valign="top"><input type="text" size="5" name="qty5"></td>
<td valign="top"><input type="text" size="10" name="cost5"
onChange="CalculateOrder(this.form)"></td>
<td valign="top"><input type="text" size="10"
name="total5"onFocus="this.form.total.focus()"></td>
</tr>
<tr>
<td valign="top"><input type="text" size="40" name="item6"></td>
<td valign="top"><input type="text" size="5" name="qty6"></td>
<td valign="top"><input type="text" size="10" name="cost6"
onChange="CalculateOrder(this.form)"></td>
<td valign="top"><input type="text" size="10"
name="total6"onFocus="this.form.total.focus()"></td>
</tr>
<tr>
<td valign="top"><input type="text" size="40" name="item7"></td>
<td valign="top"><input type="text" size="5" name="qty7"></td>
<td valign="top"><input type="text" size="10" name="cost7"
onChange="CalculateOrder(this.form)"></td>
<td valign="top"><input type="text" size="10"
name="total7"onFocus="this.form.total.focus()"></td>
</tr>
<tr>
<td colspan="3" align="right" valign="top"><strong>TOTAL COST</strong></td>
<td valign="top">$ <input type="text" size="8" name="grandtotal"
onFocus="this.form.elements[0].focus()"></td>
</tr>
</table>
</form>
</body>
</html>
noobie2005 Guest
-
form totaling
Hi. I'm having a strange problem. In this form, I enter a default value of 0 in the textfield. When the user enters all his information, and the... -
Totaling instance in an array
I need to be able to total the number of instance a product goes into to my shopping cart. I have my shopping cart array looping over a query that... -
type conversion error totaling values in array ofstructures
Hi all - I'm trying to accumulate a total from a value within an array of structures, but I keep getting a data conversion error. It refuses to... -
Help with dynaminc textboxes
I'm trying to create a button that when clicked will display text in a dynamic textbox. I've tried a lot of different things, but for once... -
Create Textboxes at run time.
Hi Kenneth, If you want to create server-side controls, then its just not that simple, although its not difficult at all. You could take a look...



Reply With Quote

