1

我正在从另一个下拉值填充下拉列表。第一次一切都很好,但是当我再次更改第一个下拉列表时,以前的值仍然显示在第二个下拉列表中。以下代码我用来填充第二个下拉列表!

<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

在第一个下拉列表中选择任何选项,从第二个中选择...然后选择第一个,第二个下拉列表保持原样!!!

4

2 回答 2

0

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

$("#NextSession").blur(function() {
  $("#NextSectionId").html(''); //emptying select field
  $("#NextSectionId").load("/GetData/" + $("#NextSession").val());
});
于 2013-05-20T10:00:04.677 回答
0

尝试将bur回调更改为change和之前使新请求清除所有旧值。

像这样的东西:

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

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

于 2013-05-20T10:02:13.893 回答