我有一個下拉菜單下面:如何在選項更改時顯示信息?
<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來顯示學生信息的學生在下拉菜單中選擇評估時選擇框?
該關鍵字是ajax。這是你試圖做的非常簡單的事情。問題是,你在這方面有什麼嘗試? – itachi
@itachi我已經做了Ajax,我已經嘗試過只是PHP,但是當我意識到我有這個問題。我嘗試了一下jquery,但深陷困境。但下面的答案將有望幫助我 – Manixman