• Resolved barnez

    (@pidengmor)


    Hi,

    I’ve been using the following formula successfully for the past few months, but I’ve just noticed yesterday that one of the fields is no longer being included in the calculation. Could this be the result of an update, as the formula has not changed?

    Below is the formula, here is the live form, and the field that is no longer calculating is fieldname10 (the discount element):

    (function(){
    var n;
    if( fieldname7<=5000 )
    {
        switch( fieldname8 )
        {
            case 5: n=2; break;
            case 4: n=1.5; break;
            case 3: n=1; break;
            case 2: n=0.95; break;
            case 1: n=0.9; break;
        }
    }
    else if( fieldname7<=10000 )
    {
        switch( fieldname8 )
        {
            case 5: return "-> Contact us"; break;
            case 4: n=2; break;
            case 3: n=1.5; break;
            case 2: n=1; break;
            case 1: n=0.95; break;
        }
    }
    else if( fieldname7<=25000 )
    {
        switch( fieldname8 )
        {
            case 5: return "-> Contact us"; break;
            case 4: return "-> Contact us"; break;
            case 3: n=1.5; break;
            case 2: n=1; break;
            case 1: n=0.95; break;
        }
    }
    else if( fieldname7<=45000 )
    {
        switch( fieldname8 )
        {
            case 5: return "-> Not available"; break;
            case 4: return "-> Not available"; break;
            case 3: return "-> Contact us"; break;
            case 2: n=1.5; break;
            case 1: n=1; break;
        }
    }
    else
    {
        switch( fieldname8 )
        {
            case 5: return "-> Not available"; break;
            case 4: return "-> Not available"; break;
            case 3: return "-> Contact us"; break;
            case 2: n=1.5; break;
            case 1: n=1; break;
        }
    }
    if( typeof n != "undefined" )
    {
    return '£'+PREC((fieldname5*fieldname7*fieldname9+(fieldname7*fieldname17)*fieldname10)*n,2);
    }
    return '';
    })()

    https://www.ads-software.com/plugins/calculated-fields-form/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hi,

    There are not issues with the update, the problem is in the equation. Please pay attention to the equation:

    return ‘£’+PREC((fieldname5*fieldname7*fieldname9+(fieldname7*fieldname17)*fieldname10)*n,2);

    The discount is the fieldname10, that is multiplied only to (fieldname7*fieldname17)*fieldname10, and not to the rest of the equation, so, the discount is applied only to this section, but the fieldname17, that represents in the form to the question: “Document formatting” has as value zero if the user select “No Thanks”, so, if the user select “No thanks” for the fieldname17, this section of the equation will be always zero:

    (fieldname7*0)*fieldname10

    I guess you have inserted the parenthesis for grouping the elements in a wrong place. To apply the discount to all the equation, and not only to a section, the correct would be:

    return ‘£’+PREC((fieldname5*fieldname7*fieldname9+(fieldname7*fieldname17))*fieldname10*n,2);

    Best regards.

    Thread Starter barnez

    (@pidengmor)

    Yes, of course you are 100% correct!

    Many thanks for highlighting the error in the formula.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘One field of form no longer being included in calculation’ is closed to new replies.