title: running autocomplete code from function error: TypeError: this.source is not a function
body: <p>I am trying to get jquery autocomplete to run its code from a function.  The reason for this is that I have about 40 fields on the form that all run the same code so I wanted to avoid repeating code as much as possible.  I have code working on another site with exactly this syntax but on the current site I am working on it throws the error.  I dont think its the jquery version as the autocomplete actually works in its simplest form.</p>
  
  <pre><code>var srch = [{value:"11",label:"Gavin"},{value:"22",label:"Greg"}];
  
  jQuery(function($) {
  /* this line returns the error */
      $( "#mytext" ).autocomplete(); { test("mytext",srch); }
  /* this line works */
  //    $( "#mytext" ).autocomplete({ source: srch });
  });
  
  function test(code,src)
  {
      $(code).autocomplete("option", "source", src);
      alert('test');
  }
  </code></pre>
  
  <p>So when I run the page with the problem line of code uncommented the alert message displays when the page loads, which indicates that the function is being called correctly, however, when I enter the first character in the field, the error occurs.  If I comment this line out and run the other that doesnt use the function, it works fine.</p>
  
  <p>This is driving me batty, its probably something very simple but im just not seeing it.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Regards</p>
  
  <p>Greg J</p>