# How To Calculate / Add Values To Total Amount

Oct 14, 2011

I followed a tutorial online on how to use Javascript to calculate total price. Everything works fine, when all the dropdown select value has it's own value and does not correspond to each other.

Eg :
Cake Type : Round \$4.00
Cake Color : Red \$3.00
Cake Filling : Raspberry \$4.00
So total is \$11.00

The problem comes when you want to add Cake Layers and the price of Cake Color changes based on No of Layers - 1 Layer , 2 Layer and so on. E.g.:
Cake Layer : Layer 1 \$5.00 | Layer 2 \$2.50 | Layer 3 \$2.50 (for color Orange)
Cake Layer : Layer 1 \$7.00 | Layer 2 \$4.00 | Layer 3 \$4.00 (for color Red)

Do I have to use if and else conditional statement for every possibility? I am just a beginner. Attached below is the example code I have so far:
var filling_prices= new Array();
filling_prices["None"]=0;
filling_prices["Lemon"]=5;
filling_prices["Custard"]=5;
filling_prices["Fudge"]=7;
filling_prices["Mocha"]=8;
filling_prices["Raspberry"]=10; .....
function getFillingPrice(){

Is there a better way of simplifying this calculation method? How do I change the price of form values based on selected values on previous dropdown.

## Cannot Calculate All Total Amount

Oct 9, 2011

<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function startCalc(){
interval = setInterval("calc()",1);
}
[Code]....

## Calculate Amount Total According To Dropdown?

Jul 9, 2011

I have a text field. I want the text field to change / be calculated on the action made on the dropdown menu... So if I select Debit card.. it should leave the amount as is..If I selected Credit Card it should add a percentage to the Amount.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

[code]....

## Calculate The Order Upon Entering A Correct Amount Showing Subtotal, Tax, And Total?

Apr 14, 2011

<html>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">[code]...

javascript coding portin of the web page.Need it to use the pop up alerts that have been input above and also to calculate the order upon entering a correct amount showing subtotal, tax, and total.

## Calculate 2 Form Values With Price And Sums With Total

Sep 20, 2009

Formfield.anzahl1 = number entered by customer
Formfield.Price1 = Ergebnisfeld1
e.g.
Anzahl1= 1
Price = 270
*if Anzahl1 = 2 then Price = 270*2

I need to do this for two form option. 2nd field would be as follows

Formfield.Anzahl2= number entered by customer
Formfield.Price2 = Ergebnisfeld2
Then Formfield.Total = Ergebnisfeld1 + Ergebnisfeld2

How can I convert these above to javascript?

## Auto Calculate The Subtraction Of Total Earn And Total Deduction?

Oct 18, 2011

I have Javascript code for auto calculate.here is the code:

<script type="text/javascript" language="javascript">
function autocalearn(oText)
{[code].....

I have a textbox for the overall total, and i want it automatic subtract the total earn and total deduction..

## Get The Total Of The Checkboxes Selected When The User Clicks The "calculate Total" Button?

Jul 18, 2011

I am trying to get the total of the checkboxes selected when the user clicks the "calculate total" button. It isn't working though.

<html>
<script type="text/javascript">

[code]....

## Total Amount Forms

Sep 20, 2005

i have the following html im just wondering how will i go about selecting a product from the list then automatically on the change showing its unique cost in the cost text field.

Then depending on the quantity purchased of that product selection and what radio button is checked (cheque add 2\$ total) (credit card increase total by 1.5 %) (cash add \$5 to the total amount) and calculate the total amount of the product. Code:

## Total Amount In Form Field

Mar 17, 2005

Say i have 4 text form fileds like this:

|-Quanitity1-|
|-Quanitity2-|
|-Quanitity3-|

|-TotalQuanitity-|

As soon as a user types in an integer into one of the quantity boxes the total quantity gets updated. How exactly would i do this? I can make it update the total quantity after a user hit's a Validate button or any button, but i cant make it update in real time.

## How 2 Calculate Subtotal Amount

May 1, 2009

if I have Subtotal amount = 10Tax rate 8.5%then Grand Total = 10 + (10 * 8.5 / 100) = 10.85Now what if I have Grand total =10.85 and tax rate 8.5% - how to calculate the Subtotal

## Calculate Each Row And Then Total

Jul 26, 2011

I am making what I call a PM (Preventive Maintenance) Kit list. My users will use this list to generate a printable sheet to tell me what they used out of there kit. The list includes pricing per part and I would like the list to calculate the costing as they enter each item. So a total per line and an overall total cost.

I have included a snap shot of the page and below is the code. I can do this sort of thing on a small scale with just adding two lines but I am not sure how to modify it to handle this scale. You can see the script towards the bottom of the page. That is my lame attempt to make the per line costing happen but NOTHING happens.

<?php
require "../config/bpts_config.php";
// Start the session
//session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
[Code]...

## Display The Total Loan Repayment Amount Instead Of The Monthly Payment

Oct 3, 2011

i want the code below to display the total loan repayment amount instead of the monthly payment payment = principle * monthly interest/(1 - (1/(1+MonthlyInterest)*Months)) , eg if if l0an is 20\$ payment is in 4 months, intrest rate is 15% display = amount to be repaid.

[Code]....

## Automatically Calculate A Total?

Oct 6, 2010

automatically calculate a total. The script pulls a price, which is given from a database to a hidden form field. Then once the quantity is changed the bottom form field automatically updates the price. Here's my script if someone could possibly point out why this might not be working (or is my logic flawed.)

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Shopping Cart</title>
<script type="text/javascript">
/* <![CDATA[ */
function calcTotal(){
[Code]...

## Getting Function To Calculate A Total

Oct 15, 2010

I can get the number of contributers to add up but not the total amount of dollars they contributed. I am not sure if my function is wrong or if I am just confused with what variable to output for the dollar amount total.

[Code]...

## Calculate A Total Dynamically?

Feb 19, 2010

1) I need to calculate a total dynamically.I have an input with the price of a product and next the amount. As the users inserts the amount I would like the total box to give the amount*price number. So if the price is 3 and user inserts:

1 - then total should display 3. Then the user inserts 0 (amount is now 10) total should display 30.The problem is that when i ask for the value in the onkeyup event of the amount input i don't get the value with the last key (same with onkeypress event). I could add that number (if it's a number) or see if it's backspace or any char but there should be an easy answer.I solved it by setting a timeout and using a callback function so as to have the latest value of the amount but it's an awfull solution (though not expensive in code).

2) Avoid focus reset when i update the value of the amount.I've managed to add commas on the fly to the amount like when the user types "1000" the number displayed is "1,000". In firefox it works great but in IE and Chrome it resets the focus each time i update the field. So when you try to move your cursor back it returns to the last position (maybe because the value of the input is changed).

here's my code:

Code:

function updatePrice(){
setTimeout(function(){callback()}, 10);
}

[code]....

## Calculate Total Only Working In IE But Not In All Browsers

Jun 10, 2009

how javascript works and have inherited a website that contains a form that uses the calculate total function...which only works in IE. I've searched all over the net trying to find a solution to get this working across all browsers but not having much luck (mostly due to lack of experience)

[Code]....

## Calculate And Display TOTAL Time On Website?

Mar 25, 2009

I have a Javascript that calculates and displays how long, in minutes and seconds a user has been in online(Google Gears development) mode on a given web page. I need however, to modify the script so that it calculates and displays how long the user has been online on the web site. For e.g. on page 1 for 2 minutes 12 seconds. Moves to page 2 - total time on page 1 and 2= 4 minutes 13 seconds. My script (see below) starts a second counter then converts that to minutes and seconds. I have tried passing the secVar0 variable in the url but that comes back "undefined".

Code:

{
c=0;

[Code]....

## Calculate And Display TOTAL Time On Website

Mar 25, 2009

I have a Javascript that calculates and displays how long, in minutes and seconds a user has been in online(Google Gears development) mode on a given web page. I need however, to modify the script so that it calculates and displays how long the user has been online on the web site. For e.g. on page 1 for 2 minutes 12 seconds. Moves to page 2 - total time on page 1 and 2= 4 minutes 13 seconds. My script (see below) starts a second counter then converts that to minutes and seconds. I have tried passing the secVar0 variable in the url but that comes back "undefined".

[Code]...

## Calculate Sum Of Multiple Input And Show Total?

Oct 31, 2009

I've been trying to check what I did wrong in my code but still the total doesn't show. Below is my javascript function:

function CalculateTotal(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)
{
var tota= document.getElementById('a');

[code].....

## Calculate Total Cost On Booking Form?

Oct 17, 2011

how to achieve client-side calculation on my company booking form, using Javascript.The total amount for accommodation is calculated based on the room type (single or twin), zone chosen and meal plan (which then assigns a certain rate per week,so for example Single room, Zone 2, Self Catering would be �165 per week). There is a table of rates here : http:[utl].....The code would then use the arrival and departure date to calculate the number of weeks, add a booking fee of �50 and output the total amount.The form is located here: http:[url]....

## Calculate The Total Time Worked On The Project?

Nov 16, 2011

There are two text boxes in a HTML form.The first text box takes the time when the user starts to work on a project. The second box takes the time when the user stops working on that project.Now, I would like to calculate the total time worked on that project for that user. That is (stop time - start time). I tried few things without success.

## Calculate Total Price In Added Tablerow

Sep 12, 2010

i have a table inside a form, with input fields ( price, qty, desc, total ( to be updated ), this works as it should with the following javascript:

<script type="text/javascript"><!--
document.forms['hours'].elements['onktotal[]'].value = (document.forms['hours'].elements['onkqty[]'].value.replace(",", ".") -0) * (document.forms['hours'].elements['onkprice[]'].value.replace(",", ".") -0);
}
//-->
</script>

now the problem occurs when i put more rows there then the javascript function does not work anymore, my ultimate goal is to create a function to add tablerows with javascript, but i'm trying to create the update function with a static situation first.

## Calculate Subtotal - Tax And Total Using Multiple Text Boxes

Apr 15, 2009

I am trying to simulate a simple checkout page where a user inputs the quantity of merchandise that they want in multiple text boxes. When they click "calculate" it calculates the subtotal, tax, and total. As it stands my calculate function works if I do quantity * price for each text box and then add together. I would have to do this 9 times! :eek: I would like to use an array but I am not exactly sure how to use it to do calculations. I know I need a loop (which I have written) and an array (which is written also).

[Code]....

## Invoice Form :: Calculate Grand Total Of Products And Add Rows?

Jun 7, 2010

I'm trying to create a Invoice form with javascript. Basically, my invoice form should have the field item, cost, quantity and product total.It shd have a function to allow the user to add rows if they want more than one item. In the end, there should be a sub total. I am able to use javascript to calc the total of each product for only the first row. If I add rows, the Product total script don't work.This is what I have so far:

Code:
<?
mysql_connect("", "", "");
mysql_select_db(invoice);[code]......

## Auto-calculate Total From Rows Added & Add Serv. Charge To Get Grandtotal?

Jun 14, 2010

I'm trying to add the total number of costs depending on the rows added to return the subtotal then later add the service charge which gives the total grand amount.I also need to add the item number when a new row is added.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

[code].....

## Sum Of Array Elements - Add And Delete Dynamic Rows And Auto Calculate The Amount Field By Multiplying Qty And Rate

Mar 21, 2011

This is my code to add and delete dynamic rows and auto calculate the amount field by multiplying qty and rate.

[Code]...