Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to populate dependable drop-down using Ajax and php [closed]

Tags:

jquery

ajax

php

Hi i want to manage data on drop-down menu using Ajax.

Databse Fields:

1.id

2.name

3.department

myDesgin.php

     <select id="id"></select>
     <select id="name"></select>
     <select id="department"></select>

1.If i selected one drop-down menu want to change another drop-downs depend on selected value using Ajax.

2.Is there any code available, if i select one drop-down it go to another child window and display data as in table format(like report) using Ajax.

Thanks in Advance.

Please give me example code, because i am beginner to ajax , most welcome if someone provide explanation with code(for ajax).

like image 864
Lydia Avatar asked Mar 23 '15 07:03

Lydia


1 Answers

Yes, check following jquery ajax code. In this example, if you change "Department" then it will populate the listing of "Name" dropdown.

$(document).on("change", '#department', function(e) {
            var department = $(this).val();
            

            $.ajax({
                type: "POST",
                data: {department: department},
                url: 'admin/users/get_name_list.php',
                dataType: 'json',
                success: function(json) {

                    var $el = $("#name");
                    $el.empty(); // remove old options
                    $el.append($("<option></option>")
                            .attr("value", '').text('Please Select'));
                    $.each(json, function(value, key) {
                        $el.append($("<option></option>")
                                .attr("value", value).text(key));
                    });														
	                

                    
                    
                }
            });

        });
like image 81
Nilesh Dharmik Avatar answered Sep 22 '22 10:09

Nilesh Dharmik