gpt4 book ai didi

mysql - Laravel-从下拉列表中选择值后自动填充输入

转载 作者:行者123 更新时间:2023-11-29 15:38:18 25 4
gpt4 key购买 nike

选择下拉列表后如何进行自动填充。我不太擅长 js 或 ajax。当用户选择 doc_no 时,必须填写 rev_no 和 title 字段。谢谢!

查看


<div class="form-group">
{!! Form::label('text', 'Doc No', ['class' => 'col-lg-3 control-label']) !!}
<div class="col-lg-10">
<select name="docNo" id="docNo" class="form-control" style="width:250px">

@foreach ($soplists as $soplist)
<option value="{{ $soplist->id }}">{{ $soplist->doc_no }}</option>
@endforeach
</select>
</div>
</div>



<input type="hidden" name="carType" value="Internal Audit" class="form-control">

<div class="form-group">
{!! Form::label('text', "Rev No", ['class' => 'col-lg-5 control-label']) !!}
<div class="col-lg-5">
<input type="text" class="form-control" id="rev" />

</div>
</div>


<div class="form-group">
{!! Form::label('text', "Title", ['class' => 'col-lg-5 control-label']) !!}
<div class="col-lg-10">
<input type="text" class="form-control" id="title" />

</div>


<script>
$('#docNo').change(function() {
var id = $(this).val();
var url = '{{ route("getDetails", ":id") }}';
url = url.replace(':id', id);

$.ajax({
url: url,
type: 'get',
dataType: 'json',
success: function(response) {
if (response != null) {
$('#rev').val(response.rev_no);
$('#title').val(response.title);
}
}
});
});
</script>

Controller ---php

   public function getDetails($id = 0)
{
$data = sopList::where('doc_no', $id)->first();
echo json_encode($data);
exit;
}
<小时/>

路线


'Route::get('get/details/{id}', 'internalAuditController@getDetails')->name('getDetails');'

数据库sop_list表图片链接

https://ibb.co/SwkJhLc

下拉菜单和输入图像

https://ibb.co/0VN3Z2y

网络选项卡

https://ibb.co/56w5BLD

最佳答案

web.php文件中添加路由:

Route::get('get/details/{id}', 'YourController@getDetails')->name('getDetails');

Controller 功能:

public function getDetails($id = 0)
{
$data = sopList::where('doc_no',$id)->first();
return response()->json($data);
}

并查看脚本:

$('#docNo').change(function(){
var id = $(this).val();
var url = '{{ route("getDetails", ":id") }}';
url = url.replace(':id', id);

$.ajax({
url: url,
type: 'get',
dataType: 'json',
success: function(response){
if(response != null){
$('#rev').val(response.rev_no);
$('#title').val(response.title);
}
}
});
});

Make sure to add the id rev and title to the rev and title input fields respectively.

关于mysql - Laravel-从下拉列表中选择值后自动填充输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57987601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com