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:
- $(document).on('focus', '.element1', function(){
- var rif= $(this).attr('rif');
- var url = 'menu/switch.php';
- var act = 'farmCompl';
- $( this ).autocomplete({
- minLength: 3,
- source: function( request, response ) {
- ajaxComplete (request, response, url, act);
- },
- select: function( event, ui ) {
- //action 1
- }
- });
- });
- $(document).on('focus', '.element2', function(){
- ...
- select: function( event, ui ) {
- //action 2
- }
- });
- });
or I can create a function of
autocomplete
that returns the values found? like this:
- function autoComp(rif) {
- var url = 'menu/switch.php';
- var act = 'farmCompl';
- $( '.'+rif ).autocomplete({
- minLength: 3,
- source: function( request, response ) {
- ajaxComplete (request, response, url, act);
- },
- select: function( event, ui ) {
- var obj = {};
- obj[0] = ui.item.id;
- obj[1] = ui.item.value;
- return obj;
- }
- });
- }
- $(document).on('focus', '.event1', function(){
- var rif= $(this).attr('rif');
- obj = autoComp(rif);
- //action1
- });
- $(document).on('focus', '.event2', function(){
- var rif= $(this).attr('rif');
- obj = autoComp(rif);
- //action2
- });
The second case is better for me.... but I've no return from the funtion
can somebody help me???
Bye