Reputation: 70466
I implemented a auto-complete function that takes an array as parameter.
$(document).ready(function(){
$('#empf').autocomplete(['black', 'white', 'red']);
}
Now I do not want a static array. Outside the document ready function I declared a function that retrieves the colors from local storage. I call this function in document ready function.
So everytime the user enters new input I want to put it in the array and use that array globally. Is that possible?
For initialisation of the array, at any point I know the number of colores stored.
So instead of the static array I put a variable e.g. data and I declare data as an array. I tried it this way:
var colors;
$(document).ready(function(){
loadColors();
$('#empf').autocomplete(colors);
}
function loadColors(){
colors = new Array(getNumColor()));
//in a loop save the colors to array using colors[i] = ...
}
But this causes my application to crash. Any ideas?
Any ideas?
Upvotes: 0
Views: 1469
Reputation: 61793
Like Rahul said this seems to be an issue of parenthesis. With firebug(another link) it is easier to detect/debug these bugs.
Also I think you should use jquery ui's autocomplete if you are not already using it(I am not sure if you are using it).
Upvotes: 2
Reputation: 187110
Seems to be an issue with parenthesis.
It should be
colors = new Array(getNumColor());
instead of
colors = new Array(getNumColor()));
Upvotes: 1