动态下拉不起作用

时间:2012-08-05 05:34:47

标签: php

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

这是我的页面代码:

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

其他一切似乎都很好......

1 个答案:

答案 0 :(得分:1)

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