• Resolved wos2021

    (@wos2021)


    Hi,

    I trying to create a form that have an number input field to calculate the input.
    This is what I trying to achieve:

    If the user puts in 40 – 60 it will cost them 10 usd.
    If the user puts in 61 – 90 it will cost 20 usd.
    If the user puts in 91 – 120 it will cost 30 usd.

    Is this possible and how can I achieve it ?

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @wos2021

    I hope you are doing well.

    You will need to use the calculation field to get the value, but, I am afraid the calculation doesn’t have a conditional, however, you can create 3 different fields based on the field conditionals.

    To find more about the calculation field: https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#calculations-field

    Fields conditional: https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#Forminator-Conditional-Logic

    Best Regards
    Patrick Freitas

    Thread Starter wos2021

    (@wos2021)

    Is it possible if you have an example ? I have tried to do this but not succeed.

    Big thanks!

    Hi @wos2021

    One possible way to accomplish this would be with a javascript snippet.

    This code reads the value of the first input field on a form, and outputs the cost to the second input field on the form:

    
    <script>
    let timer;
    const input = document.querySelector('#forminator-field-text-1');
    input.addEventListener('keyup', function (e) {
        clearTimeout(timer);
        var multiplier = 0;
        timer = setTimeout(() => {
            var amount = input.value;
            switch (true) {
                case ((amount >= 40) && (amount <= 60)):
                    multiplier = 10;
                break;
                case ((amount >= 61) && (amount <= 90)):
                    multiplier = 20;
                break;
                case ((amount >= 91) && (amount <= 120)):
                    multiplier = 30;
                break;
            }  
            document.getElementById("forminator-field-text-2").value = multiplier;
        }, 1000);
    });
    </script>

    Here’s a gif of how it looks: https://recordit.co/1DoFBvY3rh

    You can edit the IDs (#forminator-field-text-1 etc.) as needed for your form.

    Here’s a guide on some basic ways to add javascript to your site.

    Hope this helped

    Thread Starter wos2021

    (@wos2021)

    Hi @aakash8.

    This is what I needed! Thanks alot!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘If else statement number range’ is closed to new replies.