If you want to get data from database you need to call ajax on onchange event of select box.
(如果要从数据库获取数据,则需要在选择框的onchange事件上调用ajax。)
Add "setinput" class to select box
(将“ setinput”类添加到选择框)
<select type="text" name="chapter_number" class="form-control form-control-line setinput" value="">
Add below script
(添加以下脚本)
$('body').on('change','.setinput',function(){
$.ajax({
url: 'your_base_url/controller_name/your_method',
type:'POST',
data:{id:$(this).val()},
success:function(result){
$('input[name="chapter_title"]').val(result);
}
})
});
Controller method would be like below
(控制器方法如下)
public function your_method(){
$id = $this->input->post('id');
$this->db->select('*');
$this->db->from('database_table_name');
$this->db->where('chapter_number',$id);
$result = $this->db->get()->row();
echo $result->chapter_title;
}
I hope, it would be helpful to you.
(希望对您有帮助。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…