Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Help with calculating shopping total with a quantity textbox

1. ## Help with calculating shopping total with a quantity textbox

I've been given this ridiculous assignment where I have to create a shopping web page. I really need help finding the javascript codes that will allow the user to update their total as they enter the quantities of the different products in the assigned text boxes.
I don't even know where to start because we were never taught how to do this in class!

• Seems like a fun assignment to me...

What does it need to be able to do (add, delete different items, different quantitites etc.). Continue to think about this until you think you know all the things it will have to be able to do. Then come back here and explain this in a clear fashion and hopefully you will get more help.

• Originally Posted by AnnaKaren
I've been given this ridiculous assignment where I have to create a shopping web page. I really need help finding the javascript codes that will allow the user to update their total as they enter the quantities of the different products in the assigned text boxes.
I don't even know where to start because we were never taught how to do this in class!

This will give you a skeleton:-

Code:
```<form name = "myform">
PRODUCT 1 QTY <input type = "text" name = "p1" onblur = "makeTotal()"><br>
PRODUCT 2 QTY <input type = "text" name = "p2" onblur = "makeTotal()"><br>
TOTAL COST <input type = "text"  name = "tot" readonly>
</form>

<script type = "text/javascript">
function makeTotal() {
var a = Number(document.myform.p1.value);
var b = Number(document.myform.p2.value);
// you must check that the input values are positive integer numbers!
var t = a*1.20 + b *2.50;  // multiply quantities by unit price
document.myform.tot.value = t.toFixed(2);  // display total to 2 decimal places
<script>```
“A man ceases to be a beginner in any given science and becomes a master in that science when he has learned that he is going to be a beginner all his life.” Robin G. Collingwood (English Philosopher, 1889-1943)

• We are not required to make the check-out table completely interactive.
I have made mine so that the product names, codes and prices are already in the table and the user would just have to enter the quantities into a text box.

I'm just really struggling to find javascript codes that will allow the totals to accumulate the at the end of the rows as numbers are entered into the quantity box and also give an overall total at the bottom of the table.

•

1. ###### JavaScript - Calculating Total Price Based On Extra Data In Form Field - AllWebDevHelp.com
05-20-2014, 07:22 PM
2. ###### JavaScript - Simplecart Js Quantity Shipping Help Please - AllWebDevHelp.com
05-20-2014, 04:54 PM