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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作