0

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...

2
Contributors
1
Reply
9
Views
9 Months
Discussion Span
Last Post by radow
1

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.