Title: If else statement number range
Last modified: September 2, 2022

---

# If else statement number range

 *  Resolved [wos2021](https://wordpress.org/support/users/wos2021/)
 * (@wos2021)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/if-else-statement-number-range/)
 * 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](https://wordpress.org/support/users/wpmudevsupport12/)
 * (@wpmudevsupport12)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/if-else-statement-number-range/#post-15976483)
 * Hi [@wos2021](https://wordpress.org/support/users/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](https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#calculations-field)
 * Fields conditional: [https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#Forminator-Conditional-Logic](https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#Forminator-Conditional-Logic)
 * Best Regards
    Patrick Freitas
 *  Thread Starter [wos2021](https://wordpress.org/support/users/wos2021/)
 * (@wos2021)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/if-else-statement-number-range/#post-15986776)
 * Is it possible if you have an example ? I have tried to do this but not succeed.
 * Big thanks!
 *  [Aakash](https://wordpress.org/support/users/aakash8/)
 * (@aakash8)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/if-else-statement-number-range/#post-15986911)
 * Hi [@wos2021](https://wordpress.org/support/users/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: [http://recordit.co/1DoFBvY3rh](http://recordit.co/1DoFBvY3rh.gif)
 * 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](https://www.wpbeginner.com/wp-tutorials/how-to-easily-add-javascript-in-wordpress-pages-or-posts/).
 * Hope this helped
 *  Thread Starter [wos2021](https://wordpress.org/support/users/wos2021/)
 * (@wos2021)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/if-else-statement-number-range/#post-15986927)
 * Hi [@aakash8](https://wordpress.org/support/users/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.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [wos2021](https://wordpress.org/support/users/wos2021/)
 * Last activity: [3 years, 9 months ago](https://wordpress.org/support/topic/if-else-statement-number-range/#post-15986927)
 * Status: resolved