1

我想实现一个动态下拉列表,它将从第一个下拉列表中选择一批学生,然后选择相应的科目作为第二个下拉列表的选项..

这是我的页面的代码:

<head>
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
window.onload = function(){
    new JsDatePick({
        useMode:2,
        target:"inputField",
        dateFormat:"%d-%M-%Y"
    });
};
</script>
</head>
<?php
$dept =$_COOKIE[dept];
include_once("../Include/connectdb.php");
include_once("../Include/data_menu.php");
include_once '../Include/pagemaker.php';

?>
<script type="text/javascript">
$(document).ready(function()
{
$(".batch").change(function()
{
var id=$(this).val();
var dataString = 'year_join='+ id;

$.ajax
({
type: "POST",
url: "ajax_subject.php",
data: dataString,
cache: false,
success: function(html)
{
$(".subject").html(html);
} 
});

});
});
</script>

</head>

<body>

<br><br><br><br><br>
<fieldset class="cbox"><legend>Batch</legend>
<form name="frm" action=<?php print "edit_attendencePHP_NEW.php"; ?> method="GET"     

id="content">
<br><br>

<div style="margin:80px">
<label>Batch :</label> <select name="batch">
<option selected="selected">--Select Batch--</option>
<?php
    $result = mysql_query("select distinct year_joining from student_profile  

order by year_joining ")or die(mysql_error());

while($year = mysql_fetch_assoc($result)){
if($year[year_joining]!="" && $year[year_joining]>"2008"){
  print "<OPTION value='$year[year_joining]'>$dept $year[year_joining]</OPTION>";
}  }
 ?>

</select>
<label>Subject :</label> <select name="subject" class="subject">
<option selected="selected">--Choose Subject--</option>

</select>



    Date :<input type="text" size="12" id="inputField" name="date"/>
        <input class="bluebutton" type="submit" value="Go">    
 </form><br>

 <label class="comment">select a batch frm the list and press "Go"</label>
 </fieldset> 

第二个 ajax 页面工作正常......正如我用 ($_GET) 测试的那样

这是与 $_GET[year_join] (查看源代码)显示...

ajax_subject.php

<option value="ENGG.MATHS-I">ENGG.MATHS-I</option><option value="COMPUTER PROGRAMMING   
LAB">COMPUTER PROGRAMMING LAB</option><option value="WORKSHOPS">WORKSHOPS</option> 
<option value="ENGG.PHYSICS">ENGG.PHYSICS</option><option  
value="ENGG.CHEMISTRY">ENGG.CHEMISTRY</option><option ...........

其他一切似乎都很好..

4

1 回答 1

1

现在看起来没有导致 AJAX 请求的更改事件被触发,因为您的批处理选择元素没有批处理类,只有批处理名称。这就是你的意图$(".batch").change(function(){}对吗?一旦你改变了,我会在你的回调函数中放置一个警报或控制台日志,以确保它甚至可以触发。

于 2012-08-05T05:48:43.453 回答