英文:
How can i make auto fill an input form based on selectbox dropdown?
问题
我正在尝试根据选择框的选择自动填充输入表单。自动填充文本来自我的数据库。
这是我的代码:
<select style="width: 110px;" class="form-control" name="id_periodik" id="id_periodik" required oninvalid="this.setCustomValidity('Masukkan periodik sparepart!')" oninput="this.setCustomValidity('')">
<?php foreach ($periodik_options as $option) {?>
<option value="<?php echo $option['id_periodik']; ?>">
<?php echo $option['nama_periodik']; ?>
</option>
<?php }?>
</select>
</td>
基于选择自动填充文本:
<td>
<input type="text" class="form-control" id="jumlah_periodik" name="jumlah_periodik[]" readonly>
</td>
脚本:
<script>
$(document).ready(function() {
$('#id_periodik').on('change', function() {
var selectedValue = $(this).val();
$('#jumlah_periodik').val(selectedValue);
});
});
</script>
我已经尝试了这个,但在我的视图中没有任何反应。您可以提供的任何帮助我都非常感激。
英文:
I'm trying to auto fill an input form based on the selection of a selectbox. the auto fill text comes from my database
This is my code:
<select style="width: 110px;" class="form-control" name="id_periodik" id="id_periodik" required oninvalid="this.setCustomValidity('Masukkan periodik sparepart!')"
oninput="this.setCustomValidity('')">
<?php foreach ($periodik_options as $option) {?>
<option value="<?php echo $option['id_periodik']; ?>">
<?php echo $option['nama_periodik']; ?>
</option>
<?php }?>
</select>
</td>
text auto fill based on selection:
<td>
<input type="text" class="form-control" id="jumlah_periodik" name="jumlah_periodik[]" readonly>
</td>
script:
<script>
$(document).ready(function() {
$('#id_periodik').on('change', function() {
var selectedValue = $(this).val();
$('#jumlah_periodik').val(selectedValue);
});
});
</script>
i've try that but nothing happens in my view. Any help you can give I appreciate it
enter image description here
答案1
得分: -1
- 获取选定的 id_periodik
- 然后发送 AJAX 请求以从数据库获取数据
- 然后将数据设置为 jumlah_periodik
英文:
$(document).ready(function() {
$('#id_periodik').on('change', function() {
// here is the change
var selectedValue = $('#id_periodik').find(":selected").val();
$.ajax({
type : "Get",
url: 'your_url',
data: {id_periodik: selectedValue},
success:function(result){
$('#jumlah_periodik').val(result);
}
});
});
});
</script>
- Get selected id_periodik
- Then send ajax request to get data from database
- Then set data to jumlah_periodik
Hope this work
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论