1. This is my dropdown selection field inside the form
<div class="form-group">
<label>Class ID</label>
<select name="info_id" id="info_id" class="form-control info_id" required="">
<option value="">-select-</option>
@foreach($aiclasses as $aiclass)
<option value="{{$aiclass->id}}">{{$aiclass->id}}</option>
@endforeach
</select>
</div>
This is the textbox i want to autofill from db
Required FeesThis is my ajax code
@push('js')
<script>
$(".info_id").change(function() {
var id = $(this).val();
$.ajax({
url: '/info/' + $(this).val(),
type: 'get',
data: {id : 'id'},
success: function(data) {
if (data.success === true) {
$("#info_id").value = data.info;
} else {
alert('Cannot find info');
}
},
error: function(jqXHR, textStatus, errorThrown) {}
});
});
</script>
@endpush
public function getInfo($id)
{
$fill = DB::table('aiclasses')->where('id', $id)->pluck('fee');
return \Response::json(['success'=>true, 'info_area'=>$fill]);
}
答案 0 :(得分:0)
只需更新将值放入文本框的jquery代码:
$("#info_id").val(data.info_area);