Jun 18, 2016
0
Level 1
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>');
});
});
});
Please or to participate in this conversation.