Return value from a function-autocomplete

Return value from a function-autocomplete

Hi guys ... I've a question for you ... 

I'm building an application and I would like to create a common occurrence Autocomplete ... in most places I have an autocomplete the same word, but depending on where the selection has to do different things  ...
I am forced to create multiple events like this:

  1. $(document).on('focus', '.element1', function(){
  2.       var rif= $(this).attr('rif');
  3.       var url = 'menu/switch.php';
  4.       var act = 'farmCompl';
  5.       $( this ).autocomplete({
  6.             minLength: 3,
  7.             source: function( request, response ) {
  8.                   ajaxComplete (request, response, url, act);
  9.             },
  10.             select: function( event, ui ) { 
  11.             //action 1
  12.             }
  13.       });
  14. });

  1. $(document).on('focus''.element2'function(){
  2.      ...
  3.             select: functioneventui ) { 
  4.             //action 2
  5.             }
  6.       });
  7. });
or I can create a function of  autocomplete that returns the values ​​found? like this:

  1. function autoComp(rif) {
  2.       var url = 'menu/switch.php';
  3.       var act = 'farmCompl';
  4.       $( '.'+rif ).autocomplete({
  5.             minLength: 3,
  6.             source: function( request, response ) {
  7.                   ajaxComplete (request, response, url, act);
  8.             },
  9.             select: function( event, ui ) {       
  10.                   var obj = {};
  11.                   obj[0] = ui.item.id;
  12.                   obj[1] = ui.item.value;
  13.                   return obj;
  14.             }
  15.       });
  16. }
  1. $(document).on('focus', '.event1', function(){
  2.       var rif= $(this).attr('rif');
  3.       obj = autoComp(rif);
  4.       //action1
  5. });

  1. $(document).on('focus''.event2'function(){
  2.       var rif= $(this).attr('rif');
  3.       obj = autoComp(rif);
  4.       //action2
  5. });

The second case is better for me.... but I've no return from the funtion

can somebody help me???

Bye