选项更改时如何显示信息? [英] How to display information when option changes?

查看:94
本文介绍了选项更改时如何显示信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面有一个下拉菜单:

I have a drop down menu below:

<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> 

下面,我有一个多项选择"框,其中显示了一个学生列表,这些学生正在从上方的下拉菜单中进行选择评估:

Below I have a Multiple Select box where it displays a list of students that is taking the select assessment from the drop down menu above:

$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代码的问题在于必须提交页面才能找到其结果.

But I have a little problem, I need a way to be able to display the list of students in the select box when the user has selected an option from the drop down menu. The problem with the php code is that the page has to be submitted to find its results.

我的问题是,有没有一种方法可以将javascript/jQuery组合在一起,以便上面的php代码可以寻找接受所选评估的学生,但是能够使用javascript/jQuery在选择的内容中显示学生信息下拉菜单中选择评估时是否选中框?

My question is that is there a way that javascript/jQuery can be combined so that the php code above can look for the students that takes the chosen assessments but be able to use javascript/jQuery to display the student information in the select box when assessment is chosen in drop down menu?

推荐答案

您正在寻找的是php Ajax解决方案,因此您可以更新将刷新的学生列表,而无需刷新页面

What you are looking for is a php Ajax solution so you can update the list of students will be refreshed without the need to refresh the page

$('#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中,以便获得选定的值

and add this to you php so you can get the selected value

$term = $_POST['search_term'];

这是分步教程

http://www.ibm. com/developerworks/opensource/library/os-php-jquery-ajax/index.html

这篇关于选项更改时如何显示信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆