Hello,Hope all are fine.In my master-detail form, i want to show summation result of detail table grid field value. Detail table field name is return_quantity and result will show on pre_approval field of master table. I placed the below code on Table Specific->Add/Copy Page->Client Script of master table:
var $form = $('#fgrayreturn_hubadd'),
$summands = $form.find('[data-field="x_return_quantity"]'),
$sumDisplay = $('#x_pre_approval');
$form.on('change', '.form-control', function () {
var sum = 0;
$summands.each(function () {
var value = $(this).val();
value = parseFloat(value);
if (!isNaN(value)) {
sum += value;
}
});
sum = sum.toFixed(2);
$sumDisplay.val(sum);
console.log('st:', sum);
});
Using the above code first row of return_quantity field value is showing on pre_approval field of master table. But 2nd row and so on row of detail table return_quantity field value is not doing sum. Console log also showing first row value without any error. I don’t find any solution of that. Can experts identify where the mistake is and why all the rows value of details table is not doing summation and showing the result on the defined master table field?Thanks in Advance.Regards
I tried the below codes on client side event of detail table return_quantity field.
var $row = $(this).fields();
var returnqty = $row["return_quantity"].value();
var quantity = parseFloat(returnqty.replace(/,/g, ""));
console.log('quantity:', quantity);
var total = 0.00;
if (isNaN(quantity) == true) {
quantity = 0;
}
total = parseFloat(total) + quantity;
//console.log("total_qty:", total);
document.getElementById('x_pre_approval').value += total;
This codeis not workin as expected. Suppose 1st row value is 10 and 2nd row value is 120. This code is showing result 10120. Can experts please solve this problem.Regards
Hello,I am stuck on the below problem. Can any expert please give solution :
var $row = $(this).fields();
var returnqty = $row["return_quantity"].value();
var quantity = parseFloat(returnqty.replace(/,/g, ""));
console.log('quantity:', quantity);
var total = 0.00;
if (isNaN(quantity) == true) {
quantity = 0;
}
total = parseFloat(total) + quantity;
//console.log("total_qty:", total);
document.getElementById('x_pre_approval').value += total;
This code is not working as expected. Suppose 1st row value is 10 and 2nd row value is 120. This code is showing result 10120. Can experts please solve this problem.
var total = 0.00; // total is reset to 0
total = parseFloat(total) + quantity; // Add quantity of current row to total => total is always only the quantity of current row => wrong total
document.getElementById(‘x_pre_approval’).value += total; // Add quantity of current row to the existing value of the element #x_pre_approval => wrong result
>
arbei wrote:
> You should get all quantities (not just the current row) and sum them up.
Thanks for your suggesstion. I tried but don’t know how to create loop to get all quantities value instead of current row value.
Can you please help me to figure this loop.Thanks in advance.Emran
You may use jQuery (or JavaScript) to select the inputs for the quantities by the HTML attribute values. View HTML source to see the HTML attributes. Also read Inspect HTML Elements.