I have multidimensional array that include department and category.

Based on the selecting department and category, i need to search names.

below is my code

$shop = array( array( "emp_name" => "ramu", 
                      "department_name" => "cse",
                      "Number" => 15 
                    ),
               array( "emp_name" => "ramesh", 
                      "department_name" => "eee",
                      "Number" => "56",
                    ),
               array( "emp_name" => "ravi", 
                      "department_name" => "it",
                      "Number" => 7 
                    )
             );

and my jquery and auto complete code is

var resources = <?php echo json_encode($shop, JSON_FORCE_OBJECT);?>;

   jq( ".project" ).autocomplete({
            minLength: 1,
            source: resources,
            focus: function( event, ui ) {
               jq(this).val( ui.item.label );


                  return false;
               },
            select: function( event, ui ) {
               jq(this).val( ui.item.label );
                   return false;
            }
         });


         jq('.project').each(function(i, el) {
            jq(el).data('ui-autocomplete')._renderItem = function(ul, item) {
                return jq( "<li>" )
            .append( "<div class='emp-name'><a style='font-size:18px'>" + item.resources['emp_name'] + "</a><a style='font-size:13px'>" + item.resources['department_name'] + "</a></div><div id='clear'/>" )
            .appendTo( ul );
            };
        });

my html code like this

<select name="dept" id="dept">
    --
    </select>

     <select name="dept" id="dept">
    --
    </select>

    <input type="text" name="project" class="project" id="project">

after selecting dept and cate i need to display autocomplete particular emp_name
any body help me...

Hi. If you use object for source, this object have to have properties value and label

jq('.project').each(function(i, el) {
            jq(el).data('ui-autocomplete')._renderItem = function(ul, item) {
                return jq( "<li>" )
            .append( "<div class='emp-name'><a style='font-size:18px'>" + item.resources['emp_name'] + "</a><a style='font-size:13px'>" + item.resources['department_name'] + "</a></div><div id='clear'/>" )
            .appendTo( ul );
            };

this code is wrong. The Item is your object which you define in variable shop. You can call propertie

item.emp_name
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.