formsgravity-forms-plugingravitygravityforms

Gravity form automatically select value


I have gravity form. I want to do that if user select options from the drop-down then I need to also want to automatically filled others 2 filelds based on what user filled in first drop-down filed.

How can i do that?


Solution

  • If you want to go pure code, here's a basic approach:

    // Update "123" to your form ID and "1" to your Drop Down field ID.
    $( '#input_123_1' ).change( function() {
        var sourceValue = $( this ).val();
        switch( sourceValue ) {
            case 'First Choice':
                targetValue = 'You are first!';
                break;
            case 'Second Choice':
                targetValue = 'Second is nothing to sneeze at.';
                break;
            case 'Third Choice':
                targetValue = 'You know what they say about being third...';
                break;
        }
        // Update "123" to your form ID and "2" to your target field ID.
        $( '#input_123_2' ).val( targetValue );
    } );
    

    If you want to do it the easy, no-code way, checkout our plugin, Gravity Forms Populate Anything.

    The simplest approach would be to create a form that would act as your data source. On this form, you would have the possible Drop Down values and the corresponding values that should be populated when a given Drop Down value is selected.

    In your original form, you would use Populate Anything to:

    1. Populate the Drop Down options from your data source form.
    2. Populate the values that correspond with the selected Drop Down value into your other fields.

    With this approach, you can handle an infinite number of values in your Drop Down and map corresponding values to any number of additional inputs without the bulky overhead of a giant JavaScript switch case.

    If you still prefer the pure code approach, consider using our free Gravity Forms Custom JavaScript plugin that will output the JS alongside your form and ensure it executes at the right time.