DarkSpirit's avatar

How to Retrieve a Value from Json Dependent Dropdown (Laravel 5.2)

I have a problem with getting a value from a dependent dropdown (state which is dependent on a country).

Country: (A list of countries)

State: (List out the country's states depending on the country selection)

I always get ""inputState" => "+stateObj.id +" as a value from dd($request->input('inputState')) when I submitted the form which is obviously incorrect.

Js:

$('#country').on('change', function(e) {
        console.log(e);
        var country_id = e.target.value;

        //ajax
        $.getJSON("/admincms/geography/area/ajax-state?country_id="+country_id, function (data) {
            //console.log(data);
            $('#state').empty();
            $.each(data, function(index, stateObj) {
                '<option>Select a state</option>'
                $('#state').append('<option value="{{ '+stateObj.id +' }}">'+ stateObj.name +'</option>');
            });
        });
    });
0 likes
0 replies

Please or to participate in this conversation.