0

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?

2
  • What do you mean by crash? Are you getting an error message? Commented Jan 15, 2011 at 9:45
  • It breaks the interaction with the UI, the UI is just frozzen Commented Jan 15, 2011 at 9:47

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

Seems to be an issue with parenthesis.

It should be

colors = new Array(getNumColor());

instead of

colors = new Array(getNumColor()));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.