Hi,

I'm have this code below. As you can see I'm trying to use the variable clients in alert function of jqueryautocomplete.

The problem: when i select an item from the autocomplete drop-down menu it prints "undefined" instead of the value of the the var. Why?
Code:
jQuery(document).ready(function() {

  var clients = 0;

  alert(clients); //this prints 0.

  jQuery("#user_autocomplete")
  .autocomplete('autocompleteUser', jQuery.extend({}, {
    dataType: 'json',
    parse: function(data) {

      var parsed = [];
      for (key in data) {

    parsed[parsed.length] = { data: [ data[key], key ], value: data[key], result: data[key] };
      }

      return parsed;

      }
  } ))
  .result(function(event, data) {
   $('#field_users').append('<div class="user_choosen" id=' + data[1] + '>' + data[0] +'<a class="link_delete_user" href="#" onclick="javascript:deleteUser(' + data[1] +')">Delete</a></div>'); 
    $('#user_autocomplete').val(''); 

    alert(clients); //this prints undefined

  });

});
Regards

Javi