3.0 beta 2

how do you multiply two values in a table to get them to autocomplete a third cell?

Hi, I am trying to teach myself javascript so I am sorry if I appear stupid. I have a form (name="order") which I am creating to sell jewellery, on that I have a table. In the rows I have an item image in the first column, a description in the next, a price in the next which is obtained from a variable, an input box in the next where the user can put in a quantity they wish to purchase and then a subtotal cell. How do I get a value to appear in the subtotal cell when the user puts in a quantity, that is, how do I multiply the price by the quantity and get it to appear in the subtotal? I don't want to put in a 'calculate button' or similar if I can avoid it.

As I have many rows of items in the table, I know a function in the head section of the form would be best as then I could refer to it on each row. I have put some of my code for one row below. I realise that this might be easy but I am a bit lost. Thanks heaps for any help.

<!-- Invisible Set Square CZ Earrings 6mm -->
<tr style = "background-color:#FAF8CC">
<td align="center" ><a href="EInvCZStudlarge.jpg"><img border="0" width="50" height="30" align="middle" src="EInvCZStud.jpg" alt="invisible set square cz earrings 6mm" /></a></td>
<td align="left" nowrap="nowrap" width="23%"><font face="arial" size="-1" color="red"><strong>&nbsp;Invisible Set Square CZ Earrings 6mm</strong></font></td>
<td width="34%"><font face="arial" size="-1">&nbsp;</font></td>
<td width="11%" nowrap="nowrap" align="right"><font face="arial" size="-1"><script type="text/javascript">document.write(Money(InvisibleSetSquareCZEarrings6mm))</script>&nbsp;</font></td>
<td width="11%" align="center"><font face="arial" size="-1"><input name="InvisibleSetSquareCZEarrings6mm" type="text" size="1" maxlength="3" value="0"></input></font></td>
<td width="13%" nowrap="nowrap" align="right"><font face="arial" size="-1">&nbsp;</font></td>
</tr>
Steve
June 22,
Easy, put InvisibleSetSquareCZEarrings6mm in a hidden input field with an appropriate name.

Then add an input field with a QTY name, then onkeypress of that input field, the following javascript should apply:

var subTotal = document.getElementById("InvisibleSetSquareCZEarrings6mm").value * parseInt(document.getElementById("QTY").value)

There you have a variable with the subtotal in. Difficulty comes in handling multiple line items :D

Good luck. I'd suggest some other sites to learn javascript.

AcidRaZor
June 22,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.