Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Addition with Totals in a Form Table 2

Status
Not open for further replies.

Corneliu

Technical User
Sep 16, 2002
141
US
I have an invoice page where I enter all the prices and desc, etc for customers.
I have:

Quantity Desc Unit Price Total
2 xyz 13.00 26.00
3 abc 10.00 20.00

The quantity, desc, unit price are text boxes within a form. The entire table is in a form.
How can I make it so that when I fill in quantity, desc and unit price, the total automatically appears?

Than on the bottom, how can I add the total column and get a final total price for the customer?

Anyone ever done something like this? If you know where I can go and read up on it, please let me know.
 
If you stick this within a form you can use javascript ta play with your figures, you may have to stick in some data to check that the values are entered and are number format but as an initial idea how about;

either on your price input create an onblur or have a button that calls a function
<form name=&quot;frmINVOICE&quot;>
<input name=&quot;frmQTY&quot;>
<input name=&quot;frmDESC&quot;>
<input name=&quot;frmPRICE&quot; onblur=&quot;getTotal(frmINVOICE.frmQTY.value,frmINVOICE.frmPRICE.value)&quot;>
<input name=&quot;frmTOTAL&quot;>
</form>

<script language=&quot;Javascript&quot;>
function getTotal(val1,val2){
document.frmINVOICE.frmTOTAL.value = val1 * val2;
}
</script>

Depending on how many entry rows you have on your table (depending on if this is static) you can add a field that is purely for a total and each time you run your getTotal function you can call another function that adds together all the frmTOTAL depending on your naming.

How are you setting this out?

Hope this enspires you


daveJam

*Is this where we put the lonely hearts bit*
 
THANK YOU THANK YOU. Worked great.

2 more things PLEASE.

How do I make the Item Total be like $10.00 instead of 10? I do not know much javascript, and still a newbie at ASP. In ASP I know how to do it, but I see that the total comes from the Javascript code, right?


And if I want to add more than 1 entry row, do I just name the input boxes different and the total too, for example you had frmQTY and frmTOTAL for 1 item entry.

For the second one, can it be (or what's your best suggestion) like frmQTY1 and frmTOTAL1, so on and so on until I get to 10? I will add 10 entry rows.

 
As far as currency conversions go, there are many many examples out there, the first hit from google gave me this:

For the multiple rows numbering is a good idea. Personally I will number them like txtQty_0, txtQty_1, etc simply because I find it easier to read with the underscore if youhave to look at the HTML source.

The great thing about numbering them is then if you plan on using the values in the next page you can do so in a loop:
Code:
For i = 0 to 9
   If Request.Form(&quot;txtQty_&quot; & i) <> &quot;&quot; Then
      Response.Write &quot;Entry for txtQty_&quot; & i & &quot; is &quot; & Request.Form(&quot;txtQty_&quot; & i) & &quot;<br>&quot;
   Else
      Response.Write &quot;Nothing entered for txtQty_&quot; & i
   End If
Next

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Tarwn, Thankx buddy.
Since you bring up the next page, I wanted to know if the loop you wrote can be used to enter the data in the table as well.
I will be entering each item as a separate record in a ITEMS TABLE along with the customerid and the date for later use.

That would probably be better than writting the code over 10 times to write 10 records, correct?

THANK YOU VERY MUCH.
 
davejam, you said that i can put a total at the bottom depending on how many entries I have.
Sorry but I am not that good with Javascript. Can you tell me how to do that?
I tried different things, but no luck.

I have 10 entries.

THANK YOU VERY MUCH...
 
Davejam, can you still give me a hand with the totals coding? Been looking but not sure what to look for in Javascript thread.

Just wanted a total on the bottom of the entire invoice. Invoice would have 10 entries. As the person enters the prices, the bottom cell would change according to all prices entered.

THANK YOU VERY MUCH FOR YOUR HELP...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top