我有多个动态下拉列表。前一个下拉列表的值依赖于前一个下拉列表的值。我有一个下拉菜单,其中的值取决于来自两个下拉菜单的值。下拉列表的代码。
<select name="batch" id="batch-list" onChange="getSubject(this.value);" class="form-control" required>
<option value="">Select Batch</option>
</select>
<select name="semester" id="semester-list" class="form-control" required>
<option value="">Select Semester</option>
</select>
//The value of the below select are dependent on the values from batch and semester
<select name="subject" id="subject-list" class="form-control" required>
<option value="">Select Semester</option>
</select>
单个值的onchange函数:-
function getSubject(val) {
$.ajax({
type: "POST",
url: "dropdown.php",
data:'batch_id='+val,
success: function(data){
$("#subject-list").html(data);
}
});
}
上面的onchange函数只从批处理中获取值,我如何通过ajax在函数中传递学期的值
试试这个:
function getSubject(param1, param2) {
$.ajax({
type: "POST",
url: "dropdown.php",
data: {
val1 : param1,
val2 : param2
},
success: function(data){
$("#subject-list").html(data);
}
}
并命名为:
$(document).on('change', '#dropdown1_id', function(){
var dd1 = $(this).val();
var dd2 = $('#dropdown2').val();
getSubject(dd1, dd2);
});