Link to home
Start Free TrialLog in
Avatar of freshgrill
freshgrill

asked on

Calculate Total of Items in table

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
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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;

Avatar of freshgrill
freshgrill

ASKER

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.
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.
ASKER CERTIFIED SOLUTION
Avatar of freshgrill
freshgrill

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Found my own answer