# Weird shopping cart behaviour!

**URL:** <https://www.ruby-forum.com/t/weird-shopping-cart-behaviour/126964>\
**Category:** Rails\
**Created:** [January 23, 2008, 7:43pm UTC](https://www.ruby-forum.com/t/weird-shopping-cart-behaviour/126964 "2008-01-23T19:43:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xguardiola](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/13edae/32.png) [@xguardiola](https://www.ruby-forum.com/u/xguardiola)\
**Post date:** [January 23, 2008, 7:43pm UTC](https://www.ruby-forum.com/t/weird-shopping-cart-behaviour/126964/1 "2008-01-23T19:43:58Z")

</div>

Dear all,

I have a general form (which I generate via form\_tag) for a  
‘subscription’.

Inside this form the user can add ‘elements’ to his subscription. I do  
this with an an additional Ajax form:

\<% form\_remote\_tag :url =\> { :action =\> :add\_to\_cart, :id =\> element }  
do%\>  
\<%= submit\_tag “Add” %\>  
\<% end %\>

Every time the user adds an element to the cart (subscription) a table  
is updated with the list of already selected elements. In this table for  
every row another ajax form is created (rendered by a partial) to let  
the user remove the item:

\<% form\_remote\_tag :url =\> { :action =\> :delete\_from\_cart, :id =\>  
element } do%\>  
\<%= submit\_tag “Remove” %\>  
\<% end %\>

Now, the weird behaviour we find is the following:

1. I we select several elements and proceed to remove them one by one,  
we find the first Ajax Remove Form (the first button on the list) does  
not work. Instead of making an Ajax submit (as the rest of the buttons  
do) it does a regular global form submit.

2. Looking at the html code we see that for all buttons but the first,  
the Ajax submit form is created (for the first we have only the sumbmit  
button, but no Ajax form)

3. If we reload the page, all buttons work fine.

Any clues? Or maybe someone has implemented this proccess (add\_to\_cart,  
generate table with removal buttons before global submit) in some way it  
worked…

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![xguardiola](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/13edae/32.png) [@xguardiola](https://www.ruby-forum.com/u/xguardiola)\
**Post date:** [January 24, 2008, 9:22am UTC](https://www.ruby-forum.com/t/weird-shopping-cart-behaviour/126964/2 "2008-01-24T09:22:32Z")

</div>

Complex answer: You f\*cked up the DOM.  
Simple solution: Lose the table.
