Page 1 of 1

Sum of select fields

Posted: Sun Sep 02, 2018 10:52 am
by marc
Hi,
I use a series of select fields on my form, with values 0-2 (0|0|1|1|2|2). Now I want to display their total in another field (the sum of the selected values). I think a calc field would be suitable for this and that would be the easiest way.
The "only" problem is that the dropdown fields are not available in the calculator form. Is there a restriction?

Re: Sum of select fields

Posted: Sun Sep 09, 2018 12:20 am
by admin
marc,

Calc is only for Fields that only format to numbers.

One workaround would be to create a function in Javascript section of Form Properties...

Code: Select all

function addSelects(){

  var t =  $('#select_1').val() + $('#select_1').val() + $('#select_1').val() + $('#select_1').val();
   $('#the_total').val(t).change()

}
Then add addSelects() to an onchange event on each of the Selects.

Steven

Re: Sum of select fields

Posted: Sun Sep 09, 2018 1:21 am
by marc
Thank you for your support, sounds like a plan.

When I tried it with my fields, the value of the fields are concatenated, not summed up.

Re: Sum of select fields

Posted: Sun Sep 09, 2018 1:52 am
by toms
Marc, you need to cast the values to a number:

Code: Select all

Number(select_1.value) + Number(select_2.value) + ... 
or with JQuery:

Code: Select all

Number($('#select_1').val()) + Number($('#select_2').val()) + ...

Re: Sum of select fields

Posted: Wed Sep 12, 2018 4:13 am
by admin
.

Re: Sum of select fields

Posted: Sat Sep 22, 2018 3:47 am
by toms
admin wrote:marc,

Calc is only for Fields that only format to numbers.
Surprisingly, it also works fine with select elements that contain numeric values.
But you need to enter the fields manually (enable the calculator field) as they don't appear in the list of available fields.

Re: Sum of select fields

Posted: Fri Sep 28, 2018 12:22 am
by admin
.