我正在尝试将所选值传递给隐藏字段,但我总是得到选项的最后一个值。
<div class="form-group">
<label class="col-sm-3 control-label"><?php echo get_phrase('section');?></label>
<div class="col-sm-5">
<select name="section_id" class="form-control selectboxit" style="width:100%;">
<?php
foreach($sections as $row):
?>
<option value="<?php echo $row['section_id'];?>"><?php echo $row['name'];?></option>
<?php endforeach;?>
</select>
</div>
</div>
<input type="text" name="section_id" value="<?php echo $row['section_id']?>">
<div class="form-group">
<label class="col-sm-3 control-label"><?php echo get_phrase('subject');?></label>
<div class="col-sm-5">
<select name="subject_id" class="form-control selectboxit" style="width:100%;">
<?php
$subjects = $this->db->get_where('enroll' , array('section_id' => $section_id))->result_array();
foreach($subjects as $row):
?>
<option value="<?php echo $row['student_id'];?>"><?php echo $row['name'];?></option>
<?php endforeach;?>
</select>
</div>
</div>
我想将隐藏字段值传递给第二个下拉列表中的查询如何执行此操作
答案 0 :(得分:0)
您不能直接将section_id值传递给文本字段,因为它总是会给出last section_id。您应该使用以下jquery将选定的选项值分配给文本字段:
$(document).ready(function () {
$('.selectboxit').on('change', function() {
$('#section_id').val(this.value);
})
});