Hello everyone, I could really use some assistance. I am new to JavaScript and currently have a checkbox with a random value. My goal is to automatically check the checkbox when the data from the database matches the value in the checkbox.
This is how my checkbox appears:
@foreach ($loin as $loin)
<div class="custom-control custom-checkbox">
<input class="custom-control-input loincode" type="checkbox" id="{{$loin->sap_code}}" name="sap_code[]"
value="{{$loin->sap_code}}">
<label for="{{$loin->sap_code}}" class="custom-control-label">{{$loin->sap_code}}
</label>
</div>
@endforeach
Here is the corresponding JavaScript code:
$('.tampilModalUbahPts').on('click',function () {
var id = $(this).data('id');
$('.modal-body form').attr('action','/pts/'+id+'/update');
$.ajax({
url: '/ptspt/getubah',
data: {id : id},
method:'get',
dataType : 'json',
success: function (data) {
$('#lbs').val(data.lbs);
$('.loincode').attr("checked",data.loin== value);
}
});
});
Apologies for any grammatical errors in my English.