“选择”框中的选项选择不可用。我不知道是什么原因。如果通过通知检查值,则第一个选项是“ 12”。选择“ 36”也会输出“ 12”
<form action="{{ route('penpal.index', ['list'=>$list,'page' => $page]) }}" method="post">
@csrf
<select id="inputState" class="form-control" style="height:35px; width:80%" name="list" onchange="this.form.submit()">
<option value="12">@lang('penpal/component/indexMenu.twelve')</option>
<option value="24">@lang('penpal/component/indexMenu.twenty_four')</option>
<option value="36">@lang('penpal/component/indexMenu.thirty_six')</option>
</select>
</form>
alert($("#inputState").val());
答案 0 :(得分:0)
您的代码没有任何问题。您只是无法正确理解逻辑。这是我编写的代码的修改版本。如果对您有帮助,请投票给我。谢谢
//the blade form. the javascript gets the value of the selected item, assign it to the input box and submit your form automatically.
<form action="{{ route('penpal.index', ['list'=>$list,'page' => $page]) }}" method="post" id="submitForm">
{{ csrf_field() }}
<select id="inputState" class="form-control" style="height:35px; width:80%" name="list">
<option value="">-Please Select-</option>
<option value="12">@lang('penpal/component/indexMenu.twelve')</option>
<option value="24">@lang('penpal/component/indexMenu.twenty_four')</option>
<option value="36">@lang('penpal/component/indexMenu.thirty_six')</option>
</select>
<input type="text" class="form-control" id="valueid" name="id" value="">
</form>
//javascript code
<script>
$(document).ready(function(){
$("#inputState").change(function(e){
var value= e.target.value;
//alert(value);
document.getElementById('valueid').value = value; //assign select value to input field.
$('#submitForm').submit(); //submit form
});
});
</script>