Results 1 to 3 of 3
Feb 11, 2008, 14:50 #1
I am building an e-commerce and I am using some Ajax on it so each product in a listing has a button to add the product to the cart without reloading the page.
I don't know how to collect the hidden input fields in each form so they can be passed to POST.
Each product on the list has a form like this
<form class="options" action="shop/cart/add/" method="post" onsubmit="addToCart(); return false;"> <input type="hidden" size="2" name="quantity" value="1" class="priced quantity" /> <input type="hidden" name="productname" class="productname" value="product-2" /> <button type="submit">Add to cart</button> </form>
Feb 11, 2008, 15:22 #2
- Join Date
- Jan 2007
- Christchurch, New Zealand
- 62 Post(s)
- 3 Thread(s)
The form element has an elements array that references all of the form elements
So from the addToCart() function, you can use this.form.elements to get them all.Programming Group Advisor
The 2013 SitePoint Awards - Nominate your heroes now!
Feb 11, 2008, 15:39 #3
Ah, great. Many thanks.
While I waited fot an answer I have found a way to do it, but this one is much more elegant, I'll switch to your solution.