3 months ago

Old input not working when using AJAX drop down dependent list

Posted 3 months ago by ryan_160289

When I using AJAX to populate dependent drop down list and some field in form get error on validate, Laravel return back to page but value at my dependent drop down list it can't to passing old value. This is my code:

This parent dropdown to populate child dropdown, this old input working fine:

 <select class="form-control @error('country') is-invalid @enderror" name="country" id="country" value="{{ old('country') }}">
<option class="text-muted" value="" disabled selected>Chose Country</option>
  @foreach($country as $country_name => $country)
<option value="{{ $country_id }}" {{ (old('country') == $country ? "selected":"") }}>{{ $country_name}}</option>

But in this child dropdown (dependent from country) old input can't work:

 <select class="form-control @error('state') is-invalid @enderror" name="state" id="state" value="{{ old('state') }}">

How I do to this problem? Thank you.

Please sign in or create an account to participate in this conversation.