const productUrl = $("#product-container").data("url"); function createProductSelectOptions(callback) { $.ajax({ url: productUrl, method: "GET", success: function (data) { let options = ''; data.forEach((product) => { options += ``; }); callback(options); }, error: function () { alert("Gagal memuat produk."); }, }); } $(document).ready(function () { // Initial load only for the first row createProductSelectOptions((options) => { $(".product-select").first().html(options); }); // When adding a new row $(document).on("click", ".btn-add-row", function () { const row = `