views:

198

answers:

2

I need to split the string result of the autocomplete plugin. I know how to split the string and what not, but don't know how to do it in context of the plugin. Here is what I have thus far. Any help would be greatly appreciated:

 <script type="text/javascript">
     $(document).ready(function() {
         $('.divAutoComplete').autocomplete("LookupCodes.aspx?type=IC", { mustMatch: true });
     });

</script>

EDIT: I have changed it as follows and now Firebug is barking at me, saying that "value.replace is not a function" (the error is in the plugin script). Not sure what I'm doing wrong:

<script type="text/javascript">
                $(document).ready(function() {
                 $('.divAutoComplete').autocomplete("LookupCodes.aspx?type=IC", { mustMatch: true, formatItem: formatItem });
            });

     function formatItem(row) {
          var a = row[0].toString().split('--');
          return a;
                                    }

A: 

This is how I did it:

/********************************************************************************
Search Functions
********************************************************************************/
function setSearchAutoComplete()
{
     $("#txtSearchCustomer").autocomplete
               ("DataFiles/Search.ashx", 
                   {
                          formatItem: formatItem,
                          selectFirst: true,
                          minChars: 3,
                          max: 50,
                          cache: false                        
                   }
               );
    $("#txtSearchCustomer").result(findValueCallback);
}

function findValueCallback(event, data, formatted) 
{      
   $("#spnFirst").empty().html(data[0]);
   $("#spnLast").empty().html(data[1]);
   $("#spnAddress").empty().html(data[2]);    
}

function formatItem(row) 
{   
   return "<u>" + row[0]  + "</u>&nbsp;<em>" + row[1] + "</em>";
}

HTH

Raja
so is row[0] the first thing in your autocomplete dropdown result? I tried implementing like you but not sure I did it correctly. See my edit.
Matt
Its not in the format you split the data....it is in the call back.edit: And row represents the current row of data.
Raja
A: 

In my instance, I was trying to use autocomplete on a list item instead of an input element.