gpt4 book ai didi

javascript - 同一表中代码点火器中的相关下拉列表

转载 作者:行者123 更新时间:2023-11-30 15:26:09 24 4
gpt4 key购买 nike

我有一个名为“drivers”的表,其中包含 3 个字段“id”、“name”和“mob”。

我有 2 个下拉菜单。

  • 第一个下拉菜单:要显示数据库中的驾驶员姓名
  • 第二个下拉列表:要显示在第一个下拉列表中选择的驱动程序的手机号码。

请查看我现有的代码并尝试解决我的问题。这是我的代码:

抱歉,由于堆栈溢出错误,我无法在此处粘贴代码。我已在此链接上粘贴代码:here

最佳答案

//你也可以使用id和on jquery函数

 <select name="dname" class="form-control" id="selectid">
foreach($results_drivers as $row)
{
echo '<option value="'.$row->id.'">'.$row->name.'</option>';
}
</select>

get value using select box id, post driver id in controller method using
ajax function call model method in your controller method and put this
driver id in your model method's parameter and fetch reult data in success funtion

$('#selectid').on('change', function() {
var value = this.value;
var val;
var url = <?php echo base_url('admin/new_booking_validation'); ?>
$.ajax({
url: url,
type: 'POST',
data: { val: value},
success: function(result){
//now populate the mobile number in the select box.
}});
})

关于javascript - 同一表中代码点火器中的相关下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42938358/

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