0

I'm making a small grocery shopping app.

I want to make a page where the user see his/her shopping cart contents on clicking a button.

I created the template where the contents should show up in the white space. My idea is to store every item the user chooses in an array. For example:

var items = ["1 Chicken", "2 Tomatoes", "3 Spinach"]

Using this array I want to add these items line by line in the white space and then present the total amount to be paid. Kind of like a receipt. I'm not sure how to do this using JQuery.

Also, the contents of the should be empty when there's no items in the cart.

I did some research and I think I'm supposed to .html()? Though, I'm not sure about the logic behind what I want to achieve.

Here's the fiddle of the template. (The cdn links aren't working for some reason)

Could someone please help me with the logic?

1 Answer 1

1

EDIT

function getOrder()
{
   arr  = ["1 chicken","2 orange","3 milk"]
   for(i = 0;i<3;i++)
   {
     $("#elementId").append('<p>'+arr[i]+'</p><br>')
   }
}

//blank <div> tag in your page body somewhere     
<div id="elementId">

</div>
<button onclick="getOrder()">Get Order Details</button>
Sign up to request clarification or add additional context in comments.

6 Comments

Is it possible not to have it in a listview? I just want it to show up as plain text line by line in the white space
Yes, instead of ul, just have a div and keep appending <p>text...</p><br>
How would I remove the existing <p> with new ones when I make a new order? P.S the ul is not working. I'm using JQuery Mobile btw
Could you please show me how I can do it with the <p> element?
oh, JQuery mobile ?, Let me try and get back to you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.