Solved

Calculate Total of Items in table

Posted on 2010-11-17
5
698 Views
Last Modified: 2012-06-27
On a web page, an order form in a table, before user clicks on "submit/order", I want to auto summarize line items and order total (showing order table on both top and bottom of page).

example:

Order Total: $36
Item A $4  user puts in quantity 3 = auto total $12
Item B $6 user puts in quantity 4 = auto total $24
Order Total: $36
0
Comment
Question by:freshgrill
  • 3
5 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 34160532
var AUTO_TOTAL_A = parseFloat(document.getElementById("ItemAID").value) * parseInt(document.getElementById("QuantityItemAID").value);
var AUTO_TOTAL_B = parseFloat(document.getElementById("ItemBID").value) * parseInt(document.getElementById("QuantityItemBID").value);
var ORDER__TOTAL = (AUTO_TOTAL_A + AUTO_TOTAL_B).toFixed(2);
document.getElementById("autototalIDA").value = AUTO_TOTAL_A;
document.getElementById("autototalIDB").value = AUTO_TOTAL_B;
document.getElementById("ordertotalID").value = ORDER__TOTAL;

0
 

Author Comment

by:freshgrill
ID: 34169671
I don't get what I am suppose to do with that, do I have to do ItemAID, ItemBID for each row in the table? And also for the ORDER_TABLE? The number of rows are dynamic each time.
0
 
LVL 20

Expert Comment

by:ddayx10
ID: 34170004
Do you have an example of the html of the table layout you suggest? Otherwise we guess, it's a little off and we have to write code again to obtain the result you want. I understand the number of rows is dynamic, but how are the cells laid out. Show a sample html table layout and it can be done in a few min.
0
 

Accepted Solution

by:
freshgrill earned 0 total points
ID: 34173438
I found the code and example at: http://www.mcfedries.com/javascript/ordertotals.asp
0
 

Author Closing Comment

by:freshgrill
ID: 34203647
Found my own answer
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question