How to auto populated for chained selects field

jQuery(document).ready(function($) {
    $('#gform_18 #input_18_31').change(function() {
        var selectedValue = $(this).val();

        $.ajax({
            url: ajax_object.ajaxurl,
            type: 'POST',
            data: {
                action: 'update_text_field_value',
                selected_value: selectedValue
            },
            success: function(response) {
                var selected_value_parts = response.split(' ----- ');

                var value_30 = selected_value_parts[10].trim();
                var value_19 = selected_value_parts[8].trim();
                var value_5_1 = selected_value_parts[3].trim();
                var value_5_2 = selected_value_parts[4].trim();
                var value_5_3 = selected_value_parts[5].trim();
                
                $('#gform_18 #input_18_37').val(response);
                $('#gform_18 #input_18_30').val(value_30);
                $('#gform_18 #input_18_19').val(value_19);

                // Update #input_18_5_1's value to value_5_1 and trigger change event
                $('#gform_18 #input_18_5_1').val(value_5_1).change();
                
                // Update #input_18_5_2's value to value_5_2 and trigger change event
                $('#gform_18 #input_18_5_2').val(value_5_2).change();

                // Update #input_18_5_3's value to value_5_3 and trigger change event
                $('#gform_18 #input_18_5_3').val(value_5_3).change();
                
            },
            error: function(xhr, status, error) {
                console.error(xhr.responseText);
            }
        });
    });
});

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.