Laravel HTML选择输入在数据库中保存不同的值



这里我添加了简单的代码,但我想保存不同的值/数字,而不是字符串。代码如下。

<select id="select_item" class="form-control" name="sample_collection_type">
<option value="">Choose your item</option>
<option value="4500">Watch</option>
<option value="3000">Bracelet</option>
</select>
<input type="text" name="test_amount" class="form-control input_price" readonly>

在这里,我展示了带有javascript 的产品价格

<script>
$('#select_item').on('change', function() {
$('.input_price').val($(this).val());
});

</script>

在这里,我想保存1而不是4500,并相应地将2而不是3000保存到数据库中。

您需要在函数中添加变量事件"改变";。之后,您应该使用e.target.selectedIndex.

$('#select_item').on('change', function(e) {
let index = e.target.selectedIndex;
$('.input_price').val(index);
});

演示

最新更新