Reputation: 202
i want to select selected row value on button on click for this in select option i have name="product_id"
and class="productid"
i want value of product_id so i have this code
<td>
<select class="productid" name="product_id" >
@foreach($findadminproducts as $a)
<option value="{{ $a->id }}" >{{ $a->name }}</option>
@endforeach
</select>
<button onclick='linkproduct(this);'>Use Location</button>
</td>
method i tried in js
<script>
function linkproduct(button){
var b = $(this).closest("td").find('select.productid').text();
console.log(b);
}
</script>
but it gives empty value or if i use .val() then it gives undefined
Upvotes: 1
Views: 115
Reputation: 31
maybe you could try with something like this :
function linkproduct(button){
var b = $(button).closest("td").find('select option:selected' ).text();
console.log(b);
}
Upvotes: 1
Reputation: 301
try this
var b = $(button).closest("td").find('select.productid').val();
Upvotes: 1