I have a form that I intend to submit using jQuery. The following code works fine for the first time.
If the returning data equals "updated" I re-create the form within my #cart-content element. In other words: If i submit the form and it updates my cart I have a new form on my site (which has the same class, same inputs etc).
If I then click on submit again it wont trigger my jQuery code. I guess that because it's a new form that did not exist when the page was loaded so jQuery is not bound to its events and it doesnt get triggered when I submit the form.
What do I have to change to get it working? Thanks in advance!
$("form.update-cart").on("submit", function(event){
        $.post(link + "create_order/update_cart",  $(this).serialize(),  
        function(data){  
            if(data == 'updated')
            {
                var csrf_cookie = $.cookie('csrf_cookie_name');
                $("#cart-content").load(link + "create_order/display_cart", {"csrf_test_name": csrf_cookie});
            }
            else if(data == 'nothing-to-update')
            {
                return false;
            }
            else
            {  
                alert("Couldnt update cart!");  
            }  
        });  
        return false; 
});
 
    