-1
On any site, there is a list of products and these products can be added to the cart, how could I pick up the id of these products at the user click? I thought so
<div class="products">
<figure>
<img src="prod_img.png" class="product_image" />
</figure>
<h3 class="product_name">Produto X</h3>
<span class="product_price">R$ 99,90</span>
<input type="submit" productId="xxxx" class="button-add" value="Adicionar ao carrinho" />
</div>
When the user clicks on the 'Add to cart' button, javascript will pick up the product id contained within the attribute productId and send it to php so that it can add the product to the cart and return the product already added (in ajax). I could also create the cart purely in javascript by adding the data into a Document.cookie and go through the div 'products' to take the image, the name, the price and the product id and add it in the cart, when the user submits the purchase, the id will be used as a reference to the product that will be rescued from the database with php. This is doubtful of beginner, but, these solutions are used in day-to-day? Or is it just a gambiarra? What is the best method for this?
Thanks for taking my question and give me this tip of the 'Ubmit' input, I don’t have much experience with front.
– Pedro