2012-08-05 107 views
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 ........... 

一切似乎很好..

回答

1

現在它看起來像沒有改變事件,這導致了AJAX請求,被解僱了,因爲你的批處理選擇的元素沒有一個批次類,只有批次的名稱。那是你打算用$(".batch").change(function(){}對吧?一旦你改變了,我會在你的回調函數中放一個警告或控制檯日誌,以確保它甚至是正在發射。

+0

謝謝..這是類的東西.. gotcha ... – 2012-08-05 05:53:45