I have multiple select
s.
The first select
is working but when I try with the second one the jQuery does not work.
<select class="selectProduct" name="product_title[]" style="width:200px;">
@foreach($product as $value)
<option value="{{$value->id}}">{{$value->title}}</option>
@endforeach
</select>
<input type="text" name="sku[]" placeholder="Code" id ="sku" style="width:50px;" class="code" />
<input type="text" name="qty[]" placeholder="Qty" id ="qty" class="qty" style="width:50px;" />
<input type="text" name="price[]" placeholder="Price" id ="price" class="price"style="width:50px;" />
<input type="text" name="price[]" placeholder="Sale Price" id ="price" class="price"style="width:100px;" />
<br><a href="javascript:void(0);" class="add_button" title="Add field">Add</a>
Here is the second select
with the same class. The first one is working on Change. But when I click on the second select
. jQuery does not work.
<select class="selectProduct" name="product_title[]" style="width:200px;">
@foreach($product as $value)
<option value="{{$value->id}}">{{$value->title}}</option>
@endforeach
</select>
<input type="text" name="sku[]" placeholder="Code" id ="sku" style="width:50px;" class="code" />
<input type="text" name="qty[]" placeholder="Qty" id ="qty" class="qty" style="width:50px;" />
<input type="text" name="price[]" placeholder="Price" id ="price" class="price"style="width:50px;" />
<input type="text" name="price[]" placeholder="Sale Price" id ="price" class="price"style="width:100px;" />
<br><a href="javascript:void(0);" class="add_button" title="Add field">Add</a>
Here is the jQuery
$(document).ready(function(){
$('.selectProduct').change(function(){
var idSize=$(this).val();
alert(idSize);
var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
if (idSize==""){
return false;
}
$.ajax({
url:'{{route("product-price")}}',
type: 'GET',
data: {idSize: idSize},
beforeSend: function (request) {
return request.setRequestHeader('X-CSRF-Token', $("meta[name='csrf-token']").attr('content'));
},
success: function (response) {
var arr=response.split('#');
$('.price').html("$"+arr[0]+'.00');
$('.price').val(arr[0]);
$('input[name=attribute_id]').val((arr[3]));
$('.code').val((arr[4]));
},
error: function (err) {
console.log(err);
alert("Something Went Wrong, Please check again");
}
});
});
});