$(document).ready(function () { $("[id^='add_batch_']").on("click", function (e) { e.preventDefault(); var id = /\d+(?=\D*$)/.exec($(this).attr('id')); $("#div_to_append_"+id).append(`
`); }); $("[id^='div_to_append_']").on("focus", ".expiry_date_input", function (e) { $(this).datepicker({ autoclose: true, todayHighlight: true, format: 'yyyy-mm-dd' }); }); $("[id^='div_to_append_']").on("change keyup", ".new_batch_qty", function (e) { var id = /\d+(?=\D*$)/.exec($(this).attr('class')); var total_quantity = 0; //for the existing batches $(".batch_quantity_balance_"+id).each(function () { var batch_qty = $(this).val(); total_quantity += parseInt(batch_qty); }); $(".new_batch_quantity_balance_"+id).each(function () { var batch_qty = $(this).val(); total_quantity += parseInt(batch_qty); }); $("#shown_input_"+id).text(total_quantity); $("#physical_stock_"+id).val(total_quantity); // var drug_cost = $("#cost_price_"+id).val(); // var drug_price = $("#non_insured_price_"+id).val(); // var drug_system_stock = $("#system_stock_"+id).val(); // calculateDifference(id, drug_cost, drug_price, drug_system_stock); }); });