for a little shopping cart i have multiple forms on a page. Each form represents the amount of a product with a bunch of action triggers. And outside the forms i also have a couple of data which i need to use.
Anyway for this i need to get the form id corresponding to an action trigger.
So i created a function which is called when an action button is clicked.
function transferData() {
// var form_id= $(this).closest("form").prop("id");
// var form_id= $(this).prev("form").prop("id");
var form_id= $(this).closest('td').parent().closest('form').prop('id');
action is triggered by
<button name="submit[1]" type="button" onClick="transferData()" class="btn btn-info btn-sm"><i class="fa fa-refresh"></i></button>
html structure simplfy
<tr><form id="form_update[1]" name="form_update[1]" action="cart_update.php" method="post"><td data-th="Product"><div class="row">
<div class="col-sm-2 hidden-xs"><img width="100" src="../images/frere.jpg" alt="Frere" class="img-responsive"/></div>
<div class="col-sm-10">
<h4 class="nomargin">Frere</h4>
<p>bad boy frere</p>
</div>
</div></td><td data-th="Price">$25.00</td><td data-th=""> </td><td data-th="Quantity">
<input type="number" min="0" name="item_qty_summary[1]" class="form-control text-center" value="4">
</td><td data-th="Subtotal" class="text-right" >$100</td><td class="actions text-right">
<button name="submit[1]" type="submit" onClick="transferData(this)" class="btn btn-info btn-sm"><i class="fa fa-refresh"></i></button>
<a href="cart_update.php?removep=2015002&return_url=aHR0dC90aXF1ZXNob3AvaW5jbHVkZXMvdmlld19jYXJ0XzIwMTUucGhw" class="btn btn-danger btn-sm"><i class="fa fa-trash-o"></i></a>
</td></form></tr>
But i get an undefined error message and not the id
What am i overlooking??