Support » Plugin: Calculated Fields Form » How to have a minimum downpayment?

  • Resolved UserDG

    (@tenkepadu)


    I have this code

    (function(){
    var interest = 0;
    if(5001<=fieldname3 && fieldname3<=12000)
    {
    if(fieldname6 == 9) interest=0;
    else if(fieldname6 == 12) interest=0.96;
    else if(fieldname6 == 15) interest=0.9;
    else interest=0;
    }
    if(12001<=fieldname3 && fieldname3<=40000)
    {
    if(fieldname6 == 9) interest=0;
    else if(fieldname6 == 12) interest=0;
    else if(fieldname6 == 15) interest=0.84;
    else if(fieldname6 == 18) interest=0.79;
    else interest=0;
    }

    return PREC(CEIL(fieldname3-fieldname4)/(((1-1/Math.pow((1+(interest/12)),(fieldname6))))/(interest/12)),2);
    })()

    And I want to put a minimum downpayment for each price range with terms

    https://wordpress.org/plugins/calculated-fields-form/

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

    (@codepeople)

    Hi,

    The downpayment is an input field, so the users can vary its values like they want. If the minimum value allowed in this field was global (the same minimum value always), the solution is simple, enter the minimum value allowed in the “min” attribute, and that’s all. But unfortunatelly this is not the case, you want a minimum value for each price range and terms selected. I’ll give you a possible solution, but you should adapt it to your equation, if you need a custom equation, you should contact me through the support page:

    http://wordpress.dwbooster.com/support

    First, you should modify the file: “/wp-content/plugins/calculated-fields-form/js/modules/01_mathematical_logical/public/module_public.js”, to accept textual values in the calculated fields. Follow the steps below:

    1. Open the file in the text editor your choice.

    2. Go to the snippet of code:

    return isFinite( v ) || /\d{2}[\/\-\.]\d{2}[\/\-\.]\d{4}/.test( v );

    and edit it like follow:

    return typeof v != ‘undefined’;

    Now the equation:

    Suppose the following conditions: fieldname3 between 5001 and 12000, and fieldname6 equal to 9, the minimum downpayment should be 1000, or with fieldname6 equal to 12 the minimum downpayment should be 2000, or 3000 if fieldname6 is equal to 15. So, the equation would be:

    (function(){
    var interest = 0;

    if(5001<=fieldname3 && fieldname3<=12000)
    {
    if(fieldname6 == 9){ if(fieldname4 < 1000) return “The minimum downpayment allowed is 1000”; }
    else if(fieldname6 == 12){ if(fieldname4 < 2000) return “The minimum downpayment allowed is 2000”; }
    else if(fieldname6 == 15){ if(fieldname4 < 3000) return “The minimum downpayment allowed is 3000”; }
    }
    …..
    })()

    Replace the ….. by the other conditions and the rest of the equation.

    Best regards.

    Thread Starter UserDG

    (@tenkepadu)

    I try this…

    (function(){
    var interest = 0;
    var minimum = fieldname3 * 0.23;

    if(5001<=fieldname3 && fieldname3<=12000)
    {
    if(fieldname6 == 9) interest=0.98;
    { if(fieldname4 < minimum) return “The minimum downpayment allowed is”; }
    else if(fieldname6 == 12) interest=0.96;
    else if(fieldname6 == 15) interest=0.9;
    else interest=0;
    }

    But it’s not working

    Plugin Author codepeople

    (@codepeople)

    Hi,

    This equation has some basic javascript errors. The symbols {} should include all instructions in the conditional statement, the correct would be:

    if(fieldname6 == 9){
    interest=0.98;
    if(fieldname4 < minimum) return “The minimum downpayment allowed is”;
    }
    else if(fieldname6 == 12) interest=0.96;
    else if(fieldname6 == 15) interest=0.9;
    else interest=0;

    I’m sorry, but I cannot create your equations. If you need additional support contact me through our support page:

    http://wordpress.dwbooster.com/support

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to have a minimum downpayment?’ is closed to new replies.