我有一个名为的表course
。其中包含字段
COURSEID, COURSENAME
另一个名为的表STUDENTS
。其中包含
STCODE, STNAME, COURSEID
我已经预载了课程下拉列表。我想用course
从第一个下拉列表中选择的学生填充第二个下拉列表,而无需重新加载页面。
您需要进行ajax调用以在更改第一个选择框时执行此任务。下面是脚本。您可能需要包括jquery库。
$(document).ready(function()
{
$('.select').change(function() // function will work when option will change in select
{
var course_id = $('.select').val();
$.ajax({
type:"post",
url: 'getdetail.php' , // url to the php file to get the response
data:'course_id='+ course_id,
success: function(msg) {
$('.select2').html(msg);
}
});
})
})
html看起来像这样
<select class="select">
<option value="1">Course1</option>
<option value="2">Course1</option>
<option value="3">Course1</option>
</select>
<select class="select2">
<option>select1</option>
</select>
您的php文件将从db获取数据。这应该看起来像这样。getdetail.php
这只是一个示例,根据您的需要和db进行更改。
<?
$course_id=$_REQUEST['course_id']; // selected course id here
$sql_query="query here " ; // make an sql query to fetch the students from the course.
while($result)
{
echo "<option value='".$val."'>".$name."</option>"
}
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句