On 4/16/09 2:50 PM, "Lance A. Brown" <la...@bearcircle.net> wrote:

> I'm working on adding autocomplete to a form which describes a
> discussion paper.  Each paper can have multiple authors and I want to
> provide autocomplete on the author names.  I'm new to jQuery so this
> code is kind of rough.
> 
> My java script is:
> 
> // Begin
> function parse_search(data) {
>   var result = [];
>   for (var i = 0; i < data.names.length; i++) {
>     result[i] = { data: data.names[i].name,
>                   value: data.names[i].id,
>                   result: data.names[i].name
>     };
>   }
>   return result;
> }
> 
> function  format_item(row, i, max) {
>   return row;
> }
> 
> function set_author_autocomplete()
> {
>   var searchurl = $("#authsearch_url").attr("href");
> 
>   $(".author_name").each(function (i) {
>                            $(this).autocomplete(searchurl, {
>                                                 dataType: 'json',
>                                                     parse: parse_search,

what autocomplete plugin are you using? this one does not have a documented
"parse" option: 
http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions


>                                                     formatItem: format_item
>                                                     }
>                                                 )
>                              }
>                          );
> }
> 
> 
> 
> $(document).ready(set_author_autocomplete);
> //End

two more points, though i don't know if they make any odds:

it seems to be more conventional jq style (see
http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery) to put all
your jq script inside  a block like this:

 $(document).ready(function() {  });

and is there a reason to prefer:
  $(".author_name").each(function (i) { $(this).autocomplete(); });
over
  $(".author_name").autocomplete();
?


Reply via email to