I have this controller function:
public function showclientsinvoice($id)
{
$clients = Clients::find($id);
return response()->json($clients);
}
That makes me autopopulate the input fields with clients data.
My problem is I don't know how to autopopulate a dropdown list
My jquery script is this:
$(document).ready(function () {
$('body').on('click', '#show-client', function () {
var userURL = $(this).data('url');
$.get(userURL, function (data) {
$('#invoicemodal').modal('show');
$('#client-id').val(data.id);
$('#client-name').val(data.nume);
$('#client-ctara').val(data.tara);
$('#cif').val(data.cif);
$('#cif1').val(data.cif1);
$('#rgc').val(data.rgc);
$('#rgc1').val(data.rgc1);
$('#rgc2').val(data.rgc2);
$('#rgc3').val(data.rgc3);
$('#cp').val(data.cp);
$('#judet').val(data.judet);
})
});
});
</script>
How can I integrate in this script an autopopulate for dropdown?
You can use JQuery in this way to add dynamically dropdown options:
let options = {
a : 'one',
b : 'two'
};
var select = $('#idselect');
$.each(options, function(val, text) {
select.append(
$('<option></option>').val(val).html(text)
);
});