[eluser]umbungo[/eluser]
I have a (working) form to update my cart as;
Code:
//form open, id=cart_update
foreach($this->cart->contents() as $items){
$id = $items['id']; $rowID = $items['rowid']; $qty = $items['qty']; $name = $items['name'];
echo form_hidden('basket['.$id.'][rowid]', $rowid);
echo '<input type="text" name="basket['.$id.'][qty]" value="'.$qty.'">'.$name.'<br/>';
}
//submit button
This passes an array which i can put into a foreach loop to get values for multiple products and allows updating multiple items at once with one button.
I am trying to add ajax functionality. When adding items I had an add button and form for each item, and the following worked great (Jquery);
Code:
$("form.add").submit(function() {
var id = $(this).find('input[name=product_id]').val();
var qty = $(this).find('input[name=quantity]').val();
// POST, GET, HTML functions to update page.
return false;
});
But i'm not sure how to work with multiple items here.. I can't do something like add a hidden form (name='id', id=$id) because it would just be overwritten and always point to the last item. ??
I'm also not sure how to get a value of an item which is part of an array..
I attempted to retreive the values from the forms (as top) by setting a test value for 'id' in the JS, but the following still didn't work;
Code:
var id = '1234';
var id = $(this).find('input[name=basket\[' + id + '\]\[rowid\]]').val();
var qty = $(this).find('input[name=basket\[' + id + '\]\[qty\]]').val();