I have a HTML table. In each row, I have a 'Add' button along with a quantity input box, the model #, model description and price. When that button is clicked I have an onclick event which fires off our Analytics Tracking function.
On the click of the add button, I need to get the quantity from the textbox from the same row that the 'ADD' button is clicked. Currently, the only element being returned is the first row of the table. I have tried several methods using .click, .live and .on as well as .closest.
Here is the code, I hope someone can help me as I am lost trying to get this value.
HTML
<table id="ElementCount10">
<thead>
<tbody>
<tr class="odd">
<td class="image">
<div class="modelphoto link"><a rel="#"><img class="modelthumb" alt="" src="image.jpg"></a></div>
</td>
<td class="model sorting_1">
<a class="sku" href="#">Sample Part</a>
</td>
<td class="descript" rowspan="1" colspan="1">Part Description</td>
<td class="avail"><span class="instock">In Stock</span></td>
<td class="price">$318.00</td>
<td class="cart">
<input type="hidden" name="labelid" value="1234567">
<input type="hidden" name="productid" value="Part Number">
<input class="qty" type="text" name="quantity" value="" size="2" maxlength="3">
<a class="btn-primary" href="#" onclick="SiteCatalystSingleTracking('SingleAddToCart',1,this,event.target.nodeName);return false;">
</td>
</tr>
<tr class="even">
<td class="image">
<div class="modelphoto link"><a rel="#"><img class="modelthumb" alt="" src="image.jpg"></a></div>
</td>
<td class="model sorting_1"><a class="sku" href="#">Part Number</a></td>
<td class="descript" rowspan="1" colspan="1">Part Description</td>
<td class="avail"><span class="instock">In Stock</span></td>
<td class="price">$371.00</td>
<td class="cart">
<input type="hidden" name="labelid" value="1234567">
<input type="hidden" name="productid" value="Part Number">
<input class="qty" type="text" name="quantity" value="" size="2" maxlength="3">
<a class="btn-primary" href="#" onclick="SiteCatalystSingleTracking('SingleAddToCart',1,this,event.target.nodeName);return false;">
</td>
</tr>
JS
function SiteCatalystSingleTracking(carttype, requiredamt, $this, thisTarget) { // $this is the actual table to process
var parts = '';
var node = "";
var parent_path = '';
alert("T:" + thisTarget);
thisNewTarget = $(thisTarget).parents("td.cart").children("input[name=quantity]").val();
alert("NT: " + thisNewTarget);
parent_path = $($this).parents("table").attr("id");
var sku = $("#" + parent_path + " tbody tr .cart").children("input[name=productid]").val();
var qty = $("#" + parent_path + " tbody tr .cart").children("input[name=quantity]").val();
var labelid = $("#" + parent_path + " tbody tr .cart").children("input[name=labelid]").val();
}
I really need some help on this. Anything would be great!
-HeatherBear