View Full Version : Trying to get the value of a global variable inside the result() function of the jque

03-15-2011, 04:43 PM

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?

jQuery(document).ready(function() {

var clients = 0;

alert(clients); //this prints 0.

.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>');

alert(clients); //this prints undefined





EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum