2013-05-20 45 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

是試過這也.....它返回正確的值!!!! –