Reputation: 13721
Is there a way I can console.log a row's data on a select/dropdown event? For example, here is my table:
<table class="table table-striped">
<thead>
<tr>
<th style="display:none;"></th>
<th>Product Code</th>
<th>Brand</th>
<th>Category</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Item Status</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each context.order_item}}
<tr>
<td style="display:none;">{{id}}</td>
<td>{{product_code}}</td>
<td>{{brand}}</td>
<td>{{category}}</td>
<td>{{description}}</td>
<td>{{quantity}}</td>
<td>{{invoice_price}}</td>
<td>
<select id="item_status" class="item_status">
<option selected>{{status}}</option>
<option>Order Confirmed</option>
<option>Order Completed</option>
</select>
</td>
<td><button class="btn btn-danger">Cancel Item</button></td>
</tr>
{{/each}}
</tbody>
</table>
When I click my select dropdown, I want it to console.log the value of 'Brand'.. Pseudocode:
$("#.item_status").change(function() {
console.log(this.row.brand); //need to console.log the value of brand in this row
});
Can someone help?
Upvotes: 0
Views: 39
Reputation: 1283
if it will always be the 3rd cell of the row, you can do this:
$(".item_status").change(function() {
var brnd = $(this).closest('tr').find('td').eq(2).html()
console.log(brnd)
}
also, no #
on the class selector
Fiddle- https://jsfiddle.net/sx1c9xpz/
Upvotes: 1