hello guys, i want to update product dropdown value based on supplier dropdown click but in my code i have use foreach so that's why i change particular product dropdown change but output will all the product dropdown change
here is my code
@foreach($proformaInvoiceItem as $key => $list)
<tr>
<td>
<select class="form-control piliSupplierId" name="supplier" id="pili_sup_id">
@foreach(Helper::SupplierAll() as $sid)
<option value={{ $sid->id }} {{ $sid->id == $list->pili_sup_id ? 'selected' : '' }}> {{ $sid->name }}</option>
@endforeach
</select>
</td>
<td>
<select class="form-control piliProductId" name="product" id="pili_prd_id">
@foreach(Helper::productAll() as $pid)
<option value={{ $pid->id }} {{ $pid->id == $list->pili_prd_id ? 'selected' : '' }}> {{ $pid->id }} </option>
@endforeach
</select>
</td>
</tr>
@endforeach
here is my jqeury code
$('select[name="supplier"]').on('change', function () {
var id = $(this).val();
var pid = $(this).closest('.card-body').find('select[name="product"]');
$.ajax({
url: "{{url('proformainvoiceitem/fetch-products')}}",
type: "get",
data: {
sid: id,
_token: '{{csrf_token()}}'
},
dataType: 'json',
success: function (result) {
pid.empty();
$.each(result.products, function (key, value) {
console.log(value.id);
pid.append('<option value="' + value
.id + '">' + value.id + '</option>');
});
}
});
});
i want to display i have select any of supplier than change particular product dropdown change not all dropdown change but i cant