doubairan4213 2014-04-26 08:36
浏览 107

html和php中下拉列表的动态填充

I am working on student attendance system project for that i am using html and php I need the solution for this problem

i have 4 drop down list In the first drop down list contains Civil Engg,Comp Engg etc.....and so on. In the second dropdown list subject names are there that are stored in mssql database and depending on the value selected in first drop down I need to populate the subject from the database like

select * from allsubjects where branch='civilengg';

so please any give me the solution for this scenario

  • 写回答

1条回答 默认 最新

  • douzongmu2543 2014-04-26 09:11
    关注

    Here's a tutorial about Dynamic Dependent Select Box Using Ajax and jQuery that might help you

    Another solution is this:

    Put an id in your <select name="X"> code like <select name="X" id ="X">

    Put another select like <select name="Y" id="Y">. Which will be blank.

    put this jquery in your page.

    $("X").on("change",function(){
        var x_value=$("X").val();
        $.ajax({
            url:'ajax.php',
            data:{subject:x_value},
            type: 'post',
            success : function(resp){
                $("#Y").html(resp);               
            },
            error : function(resp){}
        });
    });
    

    In your ajax.php add the query.

    <?php
    $row = mysqli_query("SELECT * from allsubjects WHERE branch =".$_POST['branch']);
    while($row2 = mysqli_fetch_array($row))
        echo '<option value="' . $row2['subId'] . '">' . $row2['subName'] . '</option>
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来