如何填充从另一个下拉列表中选择值的下拉列表? [英] How to populate a dropdown list by selecting the value from another dropdown list?

查看:276
本文介绍了如何填充从另一个下拉列表中选择值的下拉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个下拉列表(HTML <选择> )。从另一个下拉列表中选择部门的价值的员工

I want to make a dropdown list (html <select>) of employees by selecting the value of department from another dropdown.

从下拉列表中谁是根据本部门的员工必须在下拉列表中显示选择部门在这里。

Here by selecting department from dropdown list the employees who are under this department must be shown in a dropdown list.

推荐答案

您应该使用AJAX为。

You should use AJAX for that.

//First combo box. where onchange event having ajax function.
<select name="parent_category" id="parent_category" onchange="change_category(this.value);" >
                                                                <option value="0">option1</option>
    <option value="1">option2</option>
    <option value="2">option3</option>
    <option value="3">option4</option>
      </select>

//Second combo box. where response of ajax call display here.
    <div class="selectbox" id="response_sub_cat">
     <select name="sub_category" id="sub_category">
     <option value="">--Choose Sub Category--</option>
     </select>
    </div>


function change_category(id)
{

        $.ajax({
            type: "POST",
            url: "ajax_get_sub_category.php?subcat="+sub_cat,
            data:   "pid=" + id,
            success: function(html){
                $("#response_sub_cat").html(html);
            }
        });
}

对于这个subcat值应该在PHP文件中的一个查询来获取子类别。 在你的情况下,其将部门员工

Regarding this subcat value there should be one query in php file to get subcategory. In your case its would be department and employees

5月份对您有所帮助。

Its may helpful to you..

Thnaks。

这篇关于如何填充从另一个下拉列表中选择值的下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆