dongye9453 2014-12-29 18:18
浏览 19

jQuery没有根据条件显示下一个下拉列表

MY logic is to make a Library Management System in which it first asks for students Class Name, than if Intermediate is selected (which is 1 in database) then show Intermediate Groups else if BS is selected than show BS Department.

<?php 

require '/include/connect.inc.php';
require '/include/core.inc.php';

?>
<script type="text/javascript" src="include/JS/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="include/JS/jQuery.js"></script>
<style>tr.Department_Options{ display: none; }</style>
<div class="articles">
    <form method="POST" action="#">
        <table align="center">
<tr><th><label for="ChoosedClassID">Class : </label></th><td><select  name="ChoosedClassID" id="ChoosedClassID"><option  disabled selected>Select Class :</option><?php 
$query="SELECT ClassID,ClassName from class ORDER BY ClassName ASC";
$query_run=mysqli_query($connect,$query) OR die(mysqli_error($connect));
while($catch=mysqli_fetch_array($query_run)) {
    $ClassName=$catch['ClassName'];
    $ClassID=$catch['ClassID']; ?>
  <option value="<?php echo $ClassID;?>"><?php echo $ClassName; ?></option> 
 <?php } ?></select><br></td></tr>

<tr id="tr_A" class="Department_Options"><th><label for="id_A">Choose Your Group : </label></th><td><select  name="InterGroupID" id="InterGroupID"><option  disabled selected>Intermediate Group :</option><?php
$query="SELECT DID,DepartmentName from department WHERE ClassID=1 ORDER BY DepartmentName ASC";
$query_run=mysqli_query($connect,$query) OR die(mysqli_error($connect));
while($catch=mysqli_fetch_array($query_run)) {
    $DepartmentName=$catch['DepartmentName'];
    $DID=$catch['DID']; ?>
  <option value="<?php echo $DID;?>"><?php echo $DepartmentName; ?></option> 
 <?php } ?></select><br></td></tr>

<tr id="tr_B" class="Department_Options"><th><label for="id_B">Choose Department : </label></th><td><select  name="DepartmentName" id="DepartmentName"><option  disabled selected>BS Department Name</option><?php
$query="SELECT DID,DepartmentName from department WHERE ClassID=2 ORDER BY DepartmentName ASC";
$query_run=mysqli_query($connect,$query) OR die(mysqli_error($connect));
while($catch=mysqli_fetch_array($query_run)) {
    $DepartmentName=$catch['DepartmentName'];
    $DID=$catch['DID']; ?>
  <option value="<?php echo $DID;?>"><?php echo $DepartmentName; ?></option> 
 <?php } ?></select><br></td></tr>
</table>                  
</form>
</div>

The jQuery.js File

$(document).ready(function(){

    $('#ChoosedClassID').on('change', function() {         

        $('tr.Department_Options').hide();
        $('#tr_' + $(this).val() ).show();

    });

});

According to code above, When I select BS,Intermediate, Next Drop Down Meny doesn't appear.

What I want is that drop down menu appear and when I select some value from it, it should ask for Student Library Number and then I want to make insert query.

  • 写回答

1条回答 默认 最新

  • drnx3715 2014-12-29 23:38
    关注

    Did you try some debugging in your JavaScript? Put temporary alert() statements in, thus:

    $(document).ready(function(){
        alert(1);
    
        $('#ChoosedClassID').on('change', function() {         
            alert(2);
    
            $('tr.Department_Options').hide();
            $('#tr_' + $(this).val() ).show();
    
        });
    
    });
    

    Do you get "1" on page load and "2" on the control change event? That's the first thing you need to do. If you do, you could perhaps move onto looking at $(this).val() to see what value that resolves to.

    As I outlined in the comments, it is worth checking your browser's console, in case any JavaScript errors pop up. Also, check your network panel to ensure your external JavaScript resources (jQuery in particular) are loaded correctly.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向