我希望使用基于下拉值的javascript将两个以上的值从视图传递到控制器!这是我的代码
<select name="class" id="class">
<option selected value='-1'>--Select class--</option>
<?php foreach($classes as $class){
echo '<option value="'.$class['class_id'].'">'.$class['class_name'].'</option>'; }
?>
</select>
<select name="subject" id="subject">
<option selected value='-1'>--Select Subject--</option>
<?php
foreach($subjects as $subject) {
echo '<option value="'.$subject['subject_id'].'">'.$subject['subject_name'].'</option>';
}
?>
</select>
<script type="text/javascript">
$(document).on("change","#class",function(e){
e.preventDefault();
var classid = $(this).val();
$.post('<?php echo site_url("system_ctrl/select_student"); ?>',{"class_id":classid},function(responce){
$("#names").html(responce);
});
</script>
我希望在使用上面显示的javascript更改类的值时,将id subject 的值与id class 的值一起发送到控制器。
答案 0 :(得分:1)
您可以传递任意数量的值,
$.post('<?php echo site_url("system_ctrl/select_student"); ?>',{"class_id":classid, "subject":$('#subject').val()},function(responce){
$("#names").html(responce);
});
答案 1 :(得分:0)
$(document).on(“change”,“#class”,function(e){e.preventDefault(); var classid = $(this).val(); .post的$( '',{ “类标识码”:CLASSID, “主题”:$( '#主题')VAL()},函数(性反应){ $( “#姓名”)HTML(性反应); }); $(document).on(“change”,“#subject”,function(e){e.preventDefault(); var subjectid = $(this).val(); .post的$( '',{ “subject_id”:subjectid, “下课”:$( '#类')VAL()},函数(性反应){ $( “#姓名”)HTML(性反应); });