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?
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Sum of select fields
Re: Sum of select fields
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...
Then add addSelects() to an onchange event on each of the Selects.
Steven
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()
}
Steven
-
- Posts: 92
- Joined: Mon May 14, 2018 3:26 pm
Re: Sum of select fields
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.
When I tried it with my fields, the value of the fields are concatenated, not summed up.
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: Sum of select fields
Marc, you need to cast the values to a number:
or with JQuery:
Code: Select all
Number(select_1.value) + Number(select_2.value) + ...
Code: Select all
Number($('#select_1').val()) + Number($('#select_2').val()) + ...
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: Sum of select fields
Surprisingly, it also works fine with select elements that contain numeric values.admin wrote:marc,
Calc is only for Fields that only format to numbers.
But you need to enter the fields manually (enable the calculator field) as they don't appear in the list of available fields.