drll42469 2014-11-19 10:46
浏览 40

如何获取选定的组合框值并以html格式加载其相应的数据

I have combobox that loads the value from data base. I want when user select value from the combobox the form should load the corresponding values from database into html form. Here is code I am trying:

<div class="col-lg-6" style="display:none"  id="c" > 
    <form id="aa" action=""   method="post"  >
        <br><br><br>

        <select name="id" id="id" class="span2" style=" width:150px;" onChange="this.form.submit();">
            <?php 
                $servername = "localhost";
                $username = "root";
                $password = "";
                $dbname = "valet";

                // Create connection
                $conn = mysqli_connect($servername, $username, $password, $dbname);
                // Check connection
                if (!$conn) {
                    die("Connection failed: " . mysqli_connect_error());
                }
                $arr = array();

                $sql = "SELECT id FROM tbl_user  ";
                $result = mysqli_query($conn, $sql);
                    // echo "User name=" . $row["name"]. "<br>";
            ?>
            <option value="">-select user-</option>
            <?php           
                if (mysqli_num_rows($result) > 0) {
                    // output data of each row
                    while($row = mysqli_fetch_assoc($result)) {
                        $arr[] = $row;
                    }

                    foreach($arr as $key => $row){
                        echo "<option value='".$row["id"]."'>".$row["id"]."</option>";
                        $GLOBALS['a'] = $row["first_name"];
                        $GLOBALS['b'] = $row["last_name"];
                        $GLOBALS['c'] = $row["phone"];
                        $GLOBALS['d'] =  $row["company_id"];
                        $GLOBALS['e'] = $row["register_on"];
                    }
                }
                else {
                    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
                    header('Location: webservices.php');
                }

                mysqli_close($conn);
            ?>
        </select>

        <br><br><br>
        <input type="text" id="first_name" value="<?php $GLOBALS['a']  ?>" name="first_name" style="width: 460px;height: 50px;overflow: hidden;" placeholder="First Name*">
        <br><br><br><br>

        <input type="text" id="last_name" value="<?php $GLOBALS['b']  ?>" name="last_name" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Last Name*">
        <br><br><br><br>
        <input type="text" id="phone" value="<?php $GLOBALS['c']  ?>" name="phone" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Phone*">
        <br><br><br><br>
        <input type="text" id="company_id" value="<?php $GLOBALS['d']  ?>" name="company_id" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Company ID*">
        <br><br><br><br>
        <input type="text" id="register_on" value="<?php $GLOBALS['e']  ?>" name="register_on" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Register On*">
        <br><br><br><br>
        <button name="edituser" id="edituser" type="submit" style="border:0;width:100px;margin-left: 45px;" >
            <img src="images/save.png" alt="">
        </button>
        <button type="submit" style="border:0;width:100px;margin-left: 75px;">
            <img src="images/cancel.png" alt="">
        </button>
    </form> 
</div> 

Please help me how I can accomplish this task?

  • 写回答

1条回答 默认 最新

  • duanhuanbo5225 2014-11-19 14:17
    关注

    You can use JQuery to do this. For the record Marco Mura did give you the solution to the problem. You just didn't want to research the problem and solve it after the solution was given to you.

    $("#id").change(function(){
        $.post("www.example.com?val=" + $(this).val(),function(response){
            $("#mydiv").html(response);
        })
    })
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端