I want to select the option city_id only 2 when after select a country value is = 1 , But I did not successfully.
HTML:
<select id="country_id">
<option></option>
@foreach($countries as $country)
<option value="{{ $country->id }}">
{{ $country->name }}
</option>
@endforeach
</select>
<select id="state_id">
</select>
<select id="city_id">
</select>
JS:
$(document).on('change', '#country_id', function() {
var country_id = $(this).val();
$('#city_id').val('2').change();
});
I see this demo
3
Answers
try this:
As it contains laravel blade syntax, you should add laravel tag as well, helps in better search results.
So, moving to question, I have taken a json response as test case.
In your controller, you can pass the json object to jquery.(or use ajax to get json response.)
For example I have used this data sample.
It gives the json response as
So passing it to jquery
HTML
Jquery
You can find demo(jsfiddle)