Javascript 无法使用codeigniter在数据库中提交选择选项
模型课程\u Model.php Controller Add_Lesson.php 查看add.phpJavascript 无法使用codeigniter在数据库中提交选择选项,javascript,php,codeigniter,Javascript,Php,Codeigniter,模型课程\u Model.php Controller Add_Lesson.php 查看add.php 章节号 挑选 章名 $(“#章_号”)。关于('change',function(){ 所选变量=$(“#章节编号”).val(); $('input[name=“chapter_title”]').val(选中); }); 我认为您在first select中使用了错误的值。您应该使用章节编号而不是标题,因为编号是一个整数,它不会像您使用章节标题那样使用字符串变量。更新你的代码 <
章节号
挑选
章名
$(“#章_号”)。关于('change',function(){
所选变量=$(“#章节编号”).val();
$('input[name=“chapter_title”]').val(选中);
});
我认为您在first select中使用了错误的值。您应该使用章节编号而不是标题,因为编号是一个整数,它不会像您使用章节标题那样使用字符串变量。更新你的代码
<div class="col-md-2 form-group">
<label class="col-sm-12">Chapter Number</label>
<div class="col-sm-9">
<select type="text" id="chapter_number" name="chapter_number" class="form-control form-control-line">
<option disabled="" selected="">Select</option>
<?php foreach($option->result() as $row) {
echo '<option value="'.$row->chapter_number.'">'.$row->chapter_number.'</option>';
}
?>
</select>
<span class="text-danger"><?php echo form_error("chapter_number"); ?></span>
</div>
章节号
挑选
哦,好的。。你看到我的截图了吗?我想这样,并在数据库中插入。。你能教我怎么做吗?首先你需要插入值,然后根据需要显示它们。我希望。。如果我选择章节号,它会自动在输入字段中显示标题。您需要使用jquery。在上选择“将章节号发送到数据库”,获取相应的记录并在文本区域中显示。我已经有剧本了,但是章节号总是零。。
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->model('lesson_model');
$this->load->database();
}
public function index() {
$data["fetch_data"] = $this->lesson_model->fetch_data();
$this->load->view("lesson/add", $data);
}
<div class="row">
<div class="col-md-2 form-group">
<label class="col-sm-12">Chapter Number</label>
<div class="col-sm-9">
<select type="text" id="chapter_number" name="chapter_number" class="form-control form-control-line">
<option disabled="" selected="">Select</option>
<?php foreach($option->result() as $row) {
echo '<option value="'.$row->chapter_title.'">'.$row->chapter_number.'</option>';
}
?>
</select>
<span class="text-danger"><?php echo form_error("chapter_number"); ?></span>
</div>
</div>
<div class="col-md-9 form-group">
<label class="col-md-12">Chapter Title</label>
<div class="col-md-10">
<input type="text" id="title" name="chapter_title" class="form-control"/>
<span class="text-danger"><?php echo form_error("chapter_title"); ?></span>
</div>
</div>
<script>
$('#chapter_number').on('change', function() {
var selected = $( "#chapter_number" ).val();
$('input[name="chapter_title"]').val(selected);
});
</script>
</div
<div class="col-md-2 form-group">
<label class="col-sm-12">Chapter Number</label>
<div class="col-sm-9">
<select type="text" id="chapter_number" name="chapter_number" class="form-control form-control-line">
<option disabled="" selected="">Select</option>
<?php foreach($option->result() as $row) {
echo '<option value="'.$row->chapter_number.'">'.$row->chapter_number.'</option>';
}
?>
</select>
<span class="text-danger"><?php echo form_error("chapter_number"); ?></span>
</div>