...

View Full Version : Resolved Help with calculating shopping total with a quantity textbox



AnnaKaren
09-27-2011, 09:08 AM
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!

ironboy
09-27-2011, 09:22 AM
Seems like a fun assignment to me... :)

Start with thinking about the logic of a shopping cart.
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.

Philip M
09-27-2011, 09:24 AM
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!

I do not see how anyone can help you very much here. Complain to your tutor.


This will give you a skeleton:-



<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)

AnnaKaren
09-27-2011, 09:44 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum