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
.val()instead of.text()onclick. Remove that attribute and use a class like<button class="linkProduct"and in jQuery (...have you included the jQuery library at all?) use$(".linkProduct").on("click", linkproduct);