2013-05-20 70 views
1

我正在从另一个下拉列表中填充drowpdown。第一次一切都很好,但是当我再次改变第一个下​​拉列表时,以前的值仍然显示在第二个下拉列表中。以下代码用于填充第二个下拉列表!jquery从其他下拉列表中下拉菜单

<select id="NextSession" name="NextSession"> 
<option value="1">Coffee</option> 
<option value="2">Tea</option> 
</select> 

<select id="NextSectionId" name="NextSectionId"> 
<option><option> 
</select> 

$("#NextSession").blur(function() { 
$("#NextSectionId").load("/GetData/" + $("#NextSession").val()); 
}); 

这里是我的PHP代码:

$UniqueId=$_GET['UniqueId']; 
$query2="select ClassName,SectionName,SectionId from class,section where class.ClassId=section.ClassId and class.ClassStatus='Active' and section.SectionStatus='Active' and class.Session='$UniqueId' order by ClassName"; 
$check2=mysql_query($query2); 
while($row2=mysql_fetch_array($check2)) 
{ 
$SelectClassName=$row2['ClassName']; 
$SelectSectionName=$row2['SectionName']; 
$SelectSectionId=$row2['SectionId']; 
echo "<option value=\"$SelectSectionId\">$SelectClassName $SelectSectionName</option>"; 
} 

请告诉我是什么问题!

这里是现场的例子!

myraipur.com/test/test.php

选择第一个下拉的任何选项,从第二个选择......然后去第一和第二下拉保持原样!

+0

试着这样做: '$( “#NextSession”)变化(函数(){ $( “#NextSectionId”)。load(“/ GetData /”+ this.value); });' –

+0

仍然面临同样的问题! –

回答

0

尝试的bur回调更改为change之前弄清楚所有旧值了新的要求。

事情是这样的:

$("#NextSession").change(function() { 
    $("#NextSectionId").empty(); 
    $("#NextSectionId").load("/GetData/" + $("#NextSession").val()); 
}); 

一些外部链接: jQuery.load jQuery.empty

+0

我已经尝试过HTML,清空,清除,重置所有功能!但他们都没有工作! –

+0

您的服务器端功能正在返回正确的数据? –

+0

是的,我每次更改下拉菜单都会从服务器获取确切的数据......但是之前的结果也包含在新的结果中! –

0

尝试清除第二选择之前加载内容

$("#NextSession").blur(function() { 
    $("#NextSectionId").html(''); //emptying select field 
    $("#NextSectionId").load("/GetData/" + $("#NextSession").val()); 
}); 
+0

也试过这个!!!!但没有解决方案! –

+0

检查数据是否仅返回选定值的内容,即1或2 – nh5

+0

是试过这也.....它返回正确的值!!!! –