Welcome to the nuBuilder Forums!

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

Subform Calculations

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
vanman
Posts: 54
Joined: Thu Mar 01, 2018 11:09 pm
Has thanked: 1 time

Subform Calculations

Unread post by vanman »

Hi

I want to calculation some fields in a subform based on who is selected in the select field. Please see attachment. subform is cli_sf_money

Thank You for your assistance
You do not have the required permissions to view the files attached to this post.
vanman
Posts: 54
Joined: Thu Mar 01, 2018 11:09 pm
Has thanked: 1 time

Re: Subform Calculations

Unread post by vanman »

Think I have solved this

Called by OnChange on the Who select object

Code: Select all

fillwhovalue()

Code: Select all

function fillwhovalue() {
 
    var whoid = $('#' + event.target.id).val();
    var prefix = $(event.target).attr('data-nu-prefix');
    var fortmon = $('#' + prefix + 'mon_fortamt').val();
    
    $('#' + prefix + 'mon_self').val(0).change();
    $('#' + prefix + 'mon_partner').val(0).change();
    $('#' + prefix + 'mon_other').val(0).change();
    
    if (whoid == 'S') {
            $('#' + prefix + 'mon_self').val(fortmon).change();
    } else if (whoid == 'P') {
            $('#' + prefix + 'mon_partner').val(fortmon).change();
    } else if (whoid == 'O') {
            $('#' + prefix + 'mon_other').val(fortmon).change();
    }
}

Is there a better way to write this?

Paul
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Subform Calculations

Unread post by kev1n »

Paul,

A bit shorter, (untested):

Code: Select all

function fillwhovalue() {

    var whoid = $('#' + event.target.id).val();
    var prefix = $(event.target).attr('data-nu-prefix');
    var fortmon = $('#' + prefix + 'mon_fortamt').val();
   
    $('#' + prefix + 'mon_self').val(whoid == 'S' ? fortmon : "0").change();
    $('#' + prefix + 'mon_partner').val(whoid == 'P' ? fortmon : "0").change();
    $('#' + prefix + 'mon_other').val(whoid == 'O' ? fortmon : "0").change();
   
}
vanman
Posts: 54
Joined: Thu Mar 01, 2018 11:09 pm
Has thanked: 1 time

Re: Subform Calculations

Unread post by vanman »

Nice will test tonight
vanman
Posts: 54
Joined: Thu Mar 01, 2018 11:09 pm
Has thanked: 1 time

Re: Subform Calculations

Unread post by vanman »

Kevin

Works great

Thanks
apmuthu
Posts: 249
Joined: Sun Dec 06, 2020 6:50 am
Location: Chennai, India, Singapore

Re: Subform Calculations

Unread post by apmuthu »

The database table (in the image in the first post) can be optimised by removing the Self, Partner, Other and Total columns and keeping the chosen value in the Amtl field alone or using an enum field to store the value directly.
Post Reply