我使用数据库创建了下拉列表,我希望以隐藏的方式发送“ center_code”值传递,而不在下拉列表中显示该值。
我的代码
<label for="student_course" control-label>STATE</label>
<div class="form-group">
<select required name="state" id="state" class="form-control input-lg dynamic" data-dependent="district">
<option value=""></option>
@foreach($state as $states)
<option value="{{ $states->state }}">{{ $states->state }}</option>
@endforeach
</select>
</div>
</div>
<div class="col-md-6">
<label for="qualification" control-label>DISTRICT</label>
<div class="form-group">
<select required name="district" id="district" class="form-control input-lg dynamic" data-dependent="taluk">
<option value=""></option>
</select>
</div>
</div>
<div class="col-md-6">
<label for="qualification" control-label>TALUK</label>
<div class="form-group">
<select required name="taluk" id="taluk" class="form-control input-lg dynamic" data-dependent="center_name">
<option value=""></option>
</select>
</div>
</div>
<div class="col-md-6">
<label for="center_name" control-label>CENTER NAME</label>
<div class="form-group">
<select required name="center_name" id="center_name" class="form-control dynamic" data-dependent="center_code">
<option value=""></option>
</select>
</div>
</div>
<input name="center_code" id="center_code" class="form-control input-lg" type="text" value="{{($(this))}}">
<div class="col-md-6">
<div class="form-group">
<select required name="center_code" id="center_code" class="form-control input-lg">
<option value=""></option>
</select>
</div>
{{ csrf_field() }}
</div>
</div>
脚本
<script>
$(document).ready(function(){
$('.dynamic').change(function(){
if($(this).val() != '')
{
var select = $(this).attr("id");
var value = $(this).val();
var dependent = $(this).data('dependent');
var _token = $('input[name="_token"]').val();
$.ajax({
url:"{{ route('dynamicdependent.fetch') }}",
method:"POST",
data:{select:select, value:value, _token:_token, dependent:dependent},
success:function(result)
{
$('#'+dependent).html(result);
}
})
}
});
$('#state').change(function(){
$('#district').val('');
$('#taluk').val('');
$('#center_name').val('');
$('#center_code').val('');
});
$('#district').change(function(){
$('#taluk').val('');
$('#center_name').val('');
$('#center_code').val('');
});
});
</script>