gpt4 book ai didi

mysql - Laravel 依赖选择值 = 0

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

将 0 值存储到 mysql 中,它应该保存在下拉列表中选择的值!请引用我在这里链接的图片!谢谢

下拉菜单 https://ibb.co/wwfxzzC

MySQL https://ibb.co/gyqLNvm

Ajax 下拉列表


$(document).ready(function() {
$('#carValidatorDept').on('change', function() {
var stateID = $(this).val();
if (stateID) {
$.ajax({
url: '/findCityWithStateID/' + stateID,
type: "GET",
data: {
"_token": "{{ csrf_token() }}"
},
dataType: "json",
success: function(data) {
//console.log(data);
if (data) {
$('#carValidatorName').empty();
$('#carValidatorName').focus;
$('#carValidatorName').append('<option value="">-- Select Validator Name --</option>');
$.each(data, function(key, value) {
$('select[name="carValidatorName"]').append('<option value="' + key + '">' + value.fname + '</option>');
});
} else {
$('#carValidatorName').empty();
}
}
});
} else {
$('#carValidatorName').empty();
}
});
});
</script>

下拉菜单


{!! Form::label('carValidatorDept', 'To: Department', ['class' => 'col-lg-2 control-label']) !!}
<div class="col-lg-10">
<select name="carValidatorDept" class="form-control" id="carValidatorDept" style="width:250px">
<option value="">-- Select dept --</option>
@foreach ($departments as $dept)
<option value="{{ $dept->id }}">{{ ucfirst($dept->name) }}</option>
@endforeach
</select>
</div>
</div>

<div class="form-group {{ ($errors->has('name'))?'has-error':'' }}">
{!! Form::label('carValidatorName', 'Name', ['class' => 'col-lg-2 control-label']) !!}
<div class="col-lg-10">


<select name="carValidatorName" class="form-control" id="carValidatorName">
</select>
</div>
</div>

最佳答案

试试这个代码:)快乐编码

 $(document).ready(function() {
$('#carValidatorDept').on('change', function() {
var stateID = $(this).val();
if (stateID) {
$.ajax({
url: '/findCityWithStateID/' + stateID,
type: "GET",
data: {
"_token": "{{ csrf_token() }}"
},
dataType: "json",
success: function(data) {
//console.log(data);
if (data) {
$('#carValidatorName').empty();
$('#carValidatorName').focus;
$('#carValidatorName').append('<option value="">-- Select Validator Name --</option>');
$.each(data, function(key, value) {
$('select[name="carValidatorName"]').append('<option value="' + value.fname + '">' + key + '</option>');
});
} else {
$('#carValidatorName').empty();
}
}
});
} else {
$('#carValidatorName').empty();
}
});
});
</script>

关于mysql - Laravel 依赖选择值 = 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58058216/

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