douji0108 2015-02-28 10:40
浏览 91
已采纳

从下拉列表中进行多项选择

Hie,I had asked this question already but I have make it briefly now please share some logic. 1st dropdown List-enter image description here Contain Class-1, class-2, class-3..etc. 2nd dropdown List-enter image description here Depends on class.If we chose class-1 and class-2 then respective Student Id will show on 2nd dropdown list. I want selected Classes in respective variables and selected turbines in respective variable. Then I will get this selected variables and use in another page.

I want multiple selection in each dropdown list. suppose I have select one Class-1 then, On the classId second dropdown list will fill with respective studentID,again I am select another class-2 then again Add respective studentID list in 2nd dropdown list.

In my databse script ClassId and StudentId this attribute present in same table only (not diffrent tables).

Table view somewhat like this->

 ClassID    StudentID   StudentNm 
      1        101         abc 
      1        102         xyz 
      1        103         jkl 
      2        201         uio
      2        202         tyu 
      3        302         qwe 
      3        305         zxc
  • 写回答

2条回答 默认 最新

  • duanputian5341 2015-02-28 11:30
    关注

    Try this

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <select multiple="multiple" name="classId" class="select-box">
        <option value="1">Option 1</option>
        <option value="2">Option 2</option>
        <option value="3">Option 3</option>
        <option value="4">Option 4</option>
        <option value="5">Option 5</option>
    </select>
    
     <script src="https://code.jquery.com/jquery-2.1.3.js"></script>
     <script>
        $('.select-box').change(function(){
            var classId = $(this).val();
    
            $.ajax({
                url : 'getSub.php',
                type: 'POST',
                dataType : 'JSON',
                data : {
                    'classId' : classId,
                },
                success : function(data){
                    console.log(data);
                }
    
            });
        });
     </script>
    </body>
    </html>
    

    When you print selectedValues values will be printed in array format. in getSub.php you can get values and send it as json

    getSub.php

    <?php
    
    $classIds = implode(',', $_POST['classId']);
    
    $stmet = "SELECT StudentID from TBL where ClassID IN ('$classIds')";
    
    $query = mysql_query($stmet);
    
    $result = mysql_fetch_array($query);
    
    echo json_encode($result);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀