Page 1 of 1

Subform Calculations

Posted: Fri Feb 05, 2021 1:45 am
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

Re: Subform Calculations

Posted: Fri Feb 05, 2021 2:28 am
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

Re: Subform Calculations

Posted: Fri Feb 05, 2021 3:41 am
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();
   
}

Re: Subform Calculations

Posted: Fri Feb 05, 2021 3:54 am
by vanman
Nice will test tonight

Re: Subform Calculations

Posted: Fri Feb 05, 2021 5:00 am
by vanman
Kevin

Works great

Thanks

Re: Subform Calculations

Posted: Sat Feb 06, 2021 2:51 am
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.