skip to Main Content

I am going to make a calculator in Gravity Forms, but I dont know if its possible to do what I want.

It should be possible for people to calculate a price on a lawn.
So I have 1 input field to square meters and then I have 3 other fields with add ons to lawn.

But the prices in the 4 other fields, depents on how many square meters the customer types in the field for square meters.

So if the customer types in between 1-25 square meters, then field 1 cost = 2 USD field 2 cost = 6 USD field 3 cost = 7 USD

But if the customer then types in from 26-40, then field 1,2,3 should cost another price.
It that possible, does anybody no that.

Thank 🙂

2

Answers


  1. I will give you the idea on how to do this via Javascript. Am assuming that Gravity Form fields accepts id attributes. Let the id attribute of each fields be in_square, field_1, field_2, and field_3

    So the fields might look like this:

    <input type="text" id="in_square" />
    
    <input type="text" id="field_1" />
    
    <input type="text" id="field_2" />
    
    <input type="text" id="field_3" />
    

    Using Javascript, you could try something like this:

    jQuery(function($){
    
      $('#in_square').on('change keyup', function(){
        var in_square = parseInt( $('#in_square').val() ),  // read the input
            field_1 = '',
            field_2 = '',
            field_3 = '';
    
        // conditions
        if( in_square >= 1 && in_square <= 25 )
        {
          field_1 = '2 USD';
          field_2 = '6 USD';
          field_3 = '7 USD';
        }
        else if( in_square >= 26 && in_square <= 40 )
        {
          field_1 = '3 USD';
          field_2 = '8 USD';
          field_3 = '10 USD';
        }
        //... and goes on..
    
        // assign the values back to the fields
        $('#field_1').val( field_1 );
        $('#field_2').val( field_2 );
        $('#field_3').val( field_3 );
      });
        
    });
    

    Here’s the fiddle: https://jsfiddle.net/xpy58b49/

    You can use the wp_enqueue_script() to inject this Javascript file.

    Login or Signup to reply.
  2. The Gravity Forms Conditional Pricing perk makes this super straightforward to setup. Here’s an rough example of how this might be configured:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search