我在下面有一个下拉菜单:
<select name="session" id="sessionsDrop">
<option value="">Please Select</option>
<option value='20'>EWYGC - 10-01-2013 - 09:00</option>
<option value='22'>WDFRK - 11-01-2013 - 10:05</option>
<option value='23'>XJJVS - 12-01-2013 - 10:00</option>
<option value='21'>YANLO - 11-01-2013 - 09:00</option>
<option value='24'>YTMVB - 12-01-2013 - 03:00</option>
</select> </p>
下面我有一个多选框,其中显示了从上面的下拉菜单中选择评估的学生列表:
$studentactive = 1;
$currentstudentqry = "
SELECT
ss.SessionId, st.StudentId, st.StudentAlias, st.StudentForename, st.StudentSurname
FROM
Student_Session ss
INNER JOIN
Student st ON ss.StudentId = st.StudentId
WHERE
(ss.SessionId = ? and st.Active = ?)
ORDER BY st.StudentAlias
";
$currentstudentstmt=$mysqli->prepare($currentassessmentqry);
// You only need to call bind_param once
$currentstudentstmt->bind_param("ii",$sessionsdrop, $stuentactive);
// get result and assign variables (prefix with db)
$currentstudentstmt->execute();
$currentstudentstmt->bind_result($dbSessionId,$dbStudentId,$dbStudentAlias,$dbStudentForename.$dbStudentSurname);
$currentstudentstmt->store_result();
$studentnum = $currentstudentstmt->num_rows();
$studentSELECT = '<select name="studenttextarea" id="studentselect" size="6">'.PHP_EOL;
if($studentnum == 0){
$studentSELECT .= "<option disabled='disabled' class='red' value=''>No Students currently in this Assessment</option>";
}else{
while ( $currentstudentstmt->fetch() ) {
$studentSELECT .= sprintf("<option disabled='disabled' value='%s'>%s - %s s</option>", $dbStudentId, $dbStudentAlias, $dbStudentForename, $dbStudentSurname) . PHP_EOL;
}
}
$studentSELECT .= '</select>';
但是我有一点问题,当用户从下拉菜单中选择了一个选项时,我需要一种能够在选择框中显示学生列表的方法。 php代码的问题是必须提交页面才能找到结果。
我的问题是,有没有一种方法可以组合javascript / jQuery,以便上面的PHP代码可以找到学生选择的评估,但能够使用javascript / jQuery在选择中显示学生信息在下拉菜单中选择评估时的框?
答案 0 :(得分:1)
您正在寻找的是一个php Ajax解决方案,因此您可以更新学生列表,无需刷新页面即可刷新
$('#sessionsDrop').change(function() {
var search_val=$(this).val();
$.post("./nameofyourphp.php", {search_term : search_val}, function(data){
if (data.length>0){
$("#divtodisplaydata").html(data);
}
})
})
并将此添加到您的PHP,以便您可以获得所选的值
$term = $_POST['search_term'];
这是一步一步的教程
http://www.ibm.com/developerworks/opensource/library/os-php-jquery-ajax/index.html