Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Sum column cells within static table

Avatar

Level 1

Hello All,

I have a static table (no possibility to add rows) with 5 rows.  Each row has a Qty cell with a dropdown list that they can select from or type their own text.  I'd like to get the grand total in the bottom footer row.

I've tried a number of combinations of the following in the calculate event of the grand total cell, which is a numeric field.  Also, I'm using javascript.

$.rawValue = Sum(Table2.Row1.Qty.rawValue, Table2.Row2.Qty.rawValue, Table2.Row3.Qty.rawValue, Table2.Row4.Qty.rawValue, Table2.Row5.Qty.rawValue);

Am I missing something?  I've tried using "+" signs between the values and removing the "$.rawValue".

Thanks in advance!

JLynn

3 Replies

Avatar

Level 10

Hi,

The syntax is FormCalc:

  • $ refers to the field with the script. The equivalent in JavaScript is "this".
  • Sum is a FormCalc function.

If you want to stick with JavaScript, then this in the total calculate event:

this.rawValue = Table2.Row1.Qty.rawValue + Table2.Row2.Qty.rawValue + Table2.Row3.Qty.rawValue + Table2.Row4.Qty.rawValue + Table2.Row5.Qty.rawValue;

Or if you want to swap to FormCalc:

$ = Sum(Table2.Row1.Qty, Table2.Row2.Qty, Table2.Row3.Qty, Table2.Row4.Qty, Table2.Row5.Qty);

See here: http://assure.ly/kUP02y.

Hope that helps,

Niall

Avatar

Level 1

Hi Niall,

Thanks so much for that explanation.  It really helped.

I've proceeded with the javascript format because I have a lot of code elsewhere in this form that is all javascript. 

I'm getting it to sum the numbers now but rather than adding them together (10+20=30) it appears to be concatenating them (10+20= 1,020).

Is there a way to fix this?  I checked to be sure it is a numeric field.

Thanks!!

Avatar

Level 10

Hi,

Make sure the Qty fields in all of the rows are NumericFields. I suspect that they are TextFields, which means that the data in them will be treated as a string and not a number. Hence the result you are getting.

You can force the script to make the inputs numeric, but it would be much better and easier if the Qty fields were numeric.

By the way, within a form you can have a mixture of JavaScript and FormCalc. The only real restriction is that you can't mix the two within the one event.

Niall