Page 1 of 1

grid sum in a textbox in the same dynaform

Posted: Mon Sep 22, 2014 6:02 am
by TingTingXie
grid total_as suggested.PNG
as suggested in the 2nd website
grid total_as suggested.PNG (19.99 KiB) Viewed 1914 times
Dear all,

I need to design a form with a grid and simple textbox which is used to store the sum total of the grid.

(Please note in the same dynaform, i know how to make the global variable and create the textbox in the next dynaform and make it shows the sum total of the grid field)

I have tried solutions like
<1> ... tal#p23151
<2> ... tal#p20685

i would like choose the 2nd approach, see pic below:
( i have changed the last line grid_myGrid.onaddrow to "myGrid.onaddrow", cause the original it always prompt me error message that this "grid_myGrid" doesn't exist.)

I have tried, problems faced: the first row whatever i keyed, the textbox will received, but the 2nd or 3rd or onwards, the textbox field stays there without any changes.
Please give me some hints or point me where i'm wrong, thanks in advance!

Really urgent! Much appreciated

Re: grid sum in a textbox in the same dynaform

Posted: Mon Sep 22, 2014 10:32 pm
by TingTingXie
Hi, guys,

although i don't know what reason, but it works fine for me now as the solution suggested.
anyway, i change the "grid add row function" to be grid_MyGrid.onaddrow = function(){}; ... _Grid_Rows

please Ctrl+F to "executing code when adding a row", thanks to everyone, cheers!

Re: grid sum in a textbox in the same dynaform

Posted: Mon Dec 23, 2019 2:31 pm
by iacsvrn
Can you give full and finish example of script?
Code: Select all

function sumGrid() {
    var noRows = Number_Rows_Grid("MyGrid", "amount");
    total = 0;
    for (var i = 1; i <=noRows; i++) {
        total += parseFloat(getGridField("MyGrid, i, "ammount).value);
    getField("Total").value = total;
//When form loads, loop through all existing rows, settings the event handler for "approved":
var totRows = Number_Rows_Grid("MyGrid", "amount");
for (var iRow = 1; iRow <= totRows; iRow++) {
    getGridField("MyGrid", iRow, "amount").onchange = sumGrid;
//set the event handler when user adds a row:
grid_MyGrid.onaddrow = function(iRow) {
    getGridField("MyGrid", iRow, "amount").onchange = sumGrid;

This one don`t work