Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Sum of select fields

Questions related to using nuBuilder Forte.
Locked
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

Sum of select fields

Unread post 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?
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Sum of select fields

Unread post 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
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

Re: Sum of select fields

Unread post 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.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Sum of select fields

Unread post 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()) + ...
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Sum of select fields

Unread post by admin »

.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Sum of select fields

Unread post 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.
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Sum of select fields

Unread post by admin »

.
Locked