【问题标题】:I want to filter one dropdown list depending on another dropdown我想根据另一个下拉列表过滤一个下拉列表
【发布时间】:2018-03-28 07:13:20
【问题描述】:

我一方面有部门,另一方面有员工。我想根据部门的选择过滤员工。我不擅长 javascipt 或 ajax。

            <div class="pure-checkbox ml-15">
               <input id="checkbox2" name="stars" type="radio" data-type="round" class="checkbox look-me" value="2">
               <label for="checkbox2"> Department </label>
            </div>
            <div id="show-me-three">
               <select class="form-control e1">
                   <option>Select</option>
               @foreach($department as $departments)
                       <option>{{ $departments->Name }}</option>
                   @endforeach
               </select>

            <div class="pure-checkbox ml-15 asset-employee-checkbox">
               <input id="checkbox6" name="stars" type="checkbox" data-type="round" class="checkbox" value="6">
               <label for="checkbox6">Employee</label>
            </div>
            <div class="asset-employee-list-show">
               <select class="form-control e1" name="ename">
                   <option>Select</option>
                       @foreach($all as $alls)
                           <option>{{ $alls->username }}</option>
                       @endforeach
               </select>
            </div>
            </div>

【问题讨论】:

标签: javascript jquery ajax laravel-5


【解决方案1】:
    <?php
     function Display_all_user()
     {
        $sql = "SELECT DISTINCT(tu.`user_name`), tu.`deleted`, tuc.`seller_id`, tu.`email_id`  FROM `tbl_user` tu, `tbl_used_car` tuc 
               WHERE tu.`email_id`=tuc.`seller_id` AND tu.`deleted`='0'";
       $result = $GLOBALS['con2']->query($sql);

      if ($result->num_rows > 0) 
      { 
         echo "<option value='0'>Select Dealer</option>";
        while($row = $result->fetch_assoc()) 
        {   
            echo "<option value='$row[email_id]'>$row[user_name]</option>";
        }
      }
    }
  ?>


    <td style="padding:10px;">
       <select id="sel_dealer" class="form-control" onchange="select_dealer(this)">
            <?php Display_all_user(); ?>
      </select>
    </td>
    <td style="padding:10px;" id="dis_brand"></td>



  -------ajax-------

                function select_dealer(ths){
                cnt=0;
                var dealer = $(ths).val();

                $.ajax({
                                    url:"MainbankAdministration/backend_code/ajax/manage_old_car_ajax.php",
                                    type:"post",
                                    data:{"filter":true,"sel_user":dealer},
                                    success:function(result){
                                        $("#dis_brand").html(result);                                              
                                        if(dealer==0){
                                            $("#dis_brand").html("");
                                            $("#dis_model").html("");
                                        }
                                    }
                                });



    --------------ajax.php---------------------
        <?php
        if(isset($_POST['filter'])){
            if(isset($_POST['sel_user']))
            {

                $sql = "SELECT DISTINCT(tcb.`brand_name`), tcb.`brand_id` FROM `tbl_used_car` tu, `tbl_car_version` tcv, `tbl_car_model` tcm, `tbl_car_brand` tcb 
                        WHERE tu.`version_id`=tcv.`version_id` 
                            AND tcm.`model_id`=tcv.`model_id` 
                            AND tcm.`brand_id`=tcb.`brand_id`
                            AND tu.`seller_id`='$_POST[sel_user]'";

                $result = $GLOBALS['con2']->query($sql);

                if ($result->num_rows > 0) 
                {
                    echo "<select class='form-control' onchange='sel_brand(this);' name='sel_brand' id='sel_brand'>
                        <option value='0'>Select Brand</option>";
                    while($row = $result->fetch_assoc()) 
                    {
                        echo "<option value='$row[brand_id]'>$row[brand_name]</option>";
                    }
                    echo "</select>";
                }

            }
        }
        ?>

【讨论】:

    猜你喜欢
    • 2018-04-16
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2021-08-19
    • 1970-01-01
    相关资源
    最近更新 更多