Javascript 2代码点火器中的条件下拉列表
地区总表: 地区表: 我有一个表单页面,其中有一个名为Category的下拉列表,在我的district表中,我保存了district code和Category name。根据类别下拉选择,需要显示地区主表中的地区名称。。。。我可以填充下拉列表,但当我这样做时,我得到的是地区代码而不是地区名称…有人请帮助 我的查看页面:Javascript 2代码点火器中的条件下拉列表,javascript,php,ajax,codeigniter,Javascript,Php,Ajax,Codeigniter,地区总表: 地区表: 我有一个表单页面,其中有一个名为Category的下拉列表,在我的district表中,我保存了district code和Category name。根据类别下拉选择,需要显示地区主表中的地区名称。。。。我可以填充下拉列表,但当我这样做时,我得到的是地区代码而不是地区名称…有人请帮助 我的查看页面: <select name="category" id="category"> <option value="Category 1">
<select name="category" id="category">
<option value="Category 1">Category 1</option>
<option value="Category 2">Category 2</option>
<option value="Category 3">Category 3</option>
</select>
<select name="placename" id="placename">
<option value="">Please select a Place</option>
</select>
型号:
function getplace()
{
$this->db->where('district_code',$this->input->post('category'));
$query = $this->db->get('district');
return $query->result();
}
剧本
<script>
jQuery(document).ready(function($) {
$("#category").on('change', function() {
var category= $(this).val();
if(category){
$.ajax ({
type: 'POST',
url: 'JcMeetingExpense/ajax_place_list',
data: { category: category},
success : function(response) {
var response = $.parseJSON(response);
$('#placename').val(response.district);
},error:function(e){
alert("error");}
});
}
});
});
</script>
jQuery(文档).ready(函数($){
$(“#类别”)。关于('change',function(){
var category=$(this.val();
如果(类别){
$.ajax({
键入:“POST”,
url:'JcMeetingExpense/ajax\u place\u list',
数据:{category:category},
成功:功能(响应){
var response=$.parseJSON(响应);
$('地名').val(response.district);
},错误:函数(e){
警报(“错误”);}
});
}
});
});
当您从数据库中获取值时,您可以简单地使用ajax来获取地区名称,并在“类别”下拉列表中单击“更改”或“模糊”,例如,您在模型部分中使用了这样的查询
function getplace()
{
$this->db->where('district_code',$this->input->post('category'));
$this->db->join('District_Master', 'district.district= District_Master.district_code');//added this
$this->db->select("District_Master.district_name");//add this
$this->db->from("district");
$query = $this->db->get();
return $query->result();
}
然后用于区域用途的下拉列表
<select><option value="//call district_code here "> //call district_name here</option></select>
//在这里调用地区名称
用你的对象调用上面的东西,因为你说你已经在下拉列表中填充了数据。这可能是一个错误。如果有任何错误,请尝试和评论。我认为在
地区
表列(地区
)中类似于地区主管
表列(地区代码
)
在模型中使用与区域主表的内部联接
$this->db->select('*');
$this->db->from('district');
$this->db->join('District_Master', 'district.district= District_Master.district_code');
$this->db->where('district.district_code',$this->input->post('category'));
$query = $this->db->get();
使用此查询,您可以从
district\u master
表中获取姓名,您可以在下拉列表中使用姓名将图像添加到问题中,而不是外部图像链接,并显示您的代码我已编辑我的问题,请查看我已添加答案,如果您有更多查询,请告诉我
$this->db->select('*');
$this->db->from('district');
$this->db->join('District_Master', 'district.district= District_Master.district_code');
$this->db->where('district.district_code',$this->input->post('category'));
$query = $this->db->get();