[JavaScript] Need help on fixing my 'for' loop which will calculate the total price for each item a user selects
I am working on a school project which requires creating an interactive menu using JavaScript, (first JavaScript project). My menu allows the user to theoretically buy uniform clothes (the assignment does not require payment options). My menu has 21 rows, 1 for each type of clothing (jerseys, shorts, white t-shirt) etc. with a corresponding size and quantity for a user to select. I have done a 'confirm order' for each item which will confirm the order for a separate item. E.g. selecting a small sized blazer will bring up the following confirm message 'You have chosen to order 1 small Blazers for $200. Confirm?'. When clicking 'yes' it will result in the alert prompt 'Order Confirmed'. So I have done this for each item and I have made a 'for' loop which is suppose to calculate the total price for each item a user selects. The problem is I don't know what is wrong with my 'for' loop and need help fixing it, so it can calculate the total price. Once it calculates the total price for each item, I am planning to display an alert message which will display the total items and price the user has ordered. After this, I am planning to do a final confirm message along the lines of 'Do you wish to confirm this order?' and if the user proceeds then they will be greeted with a 'thank you for ordering' html page. Here is my following html and JavaScript code: http://jsfiddle.net/zDQML/6/ Note: I am inexperienced in JavaScript and relatively new at it so I have a small amount of knowledge as you can tell from the multiple functions and lack of arrays
@dumbsearch2 JS Question... if you happen to log on.
K so there are many problems in the code. First of all you have added a semicolon after for loop which terminates the loop. But apart from that you have to change the id's of your quantity field to make it work easily. Make the default quantity ZERO I have made change in the JSfiddle have a look. http://jsfiddle.net/zDQML/10/
DAMNIT I always come too late :\
Before you commented on this I was working on my code for a bit and this is what I ended up with. What could I do to fix it so it only calculates the total price for items that the user has selected? http://jsfiddle.net/WLQAk/
If my version doesn't work then, how would I change the id's of my quantity field to make it work easily to your updated version, like you said
Whats wrong, exactly?
Tell me clearly :)
I need to calculate the total price for each item a user selects
but idk how to do that
Like say a user wanted 1 small sized blazer and 2 white t shirts. When the user clicks on confirm total it will bring an alert/confirm "You have ordered the following 1 small sized blazer and 2 white t shirts" "Do you wish to confirm this order". something along those lines but idk how to do that
Think i need to do another array
Join our real-time social learning platform and learn together with your friends!