如何填充从另一个下拉列表中选择值的下拉列表?列表、列表中

2023-09-10 17:10:39 作者:孤心

我想打一个下拉列表(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。