Reputation: 2896
I am trying to retrieve data from database and send it to a form as value, but the problem is it shows the first item of the dropdown list. I want the value that comes from the db, appears as selected.
<!-- Select Service status -->
<div class="form-group">
<label class="col-md-4 control-label" for="service_status">Service Status</label>
<div class="col-md-4">
<select id="service_status" name="service_status" class="form-control" value="{{ $job_account_detail->service_status }}">
<option value="Pending">Pending</option>
<option value="Running">Running</option>
<option value="Completed">Completed</option>
</select>
</div>
</div>
Upvotes: 2
Views: 3169
Reputation: 7303
You can change your code to something like this:
<div class="form-group">
<label class="col-md-4 control-label" for="service_status">Service Status</label>
<div class="col-md-4">
<select id="service_status" name="service_status" class="form-control">
<option value="Pending" {{ $job_account_detail->service_status=="Pending" ? "selected" : ''}}>Pending</option>
<option value="Running" {{ $job_account_detail->service_status=="Running" ? "selected" : ''}}>Running</option>
<option value="Completed" {{ $job_account_detail->service_status=="Completed" ? "selected" : ''}}>Completed</option>
</select>
</div>
</div>
Upvotes: 3