1

i've created a JQuery UI Autocomplete in which the source is an array of label-value pairs. i need to set the default selected item. i found a way to do that using the desired label, but how can i do that if i have the VALUE instead of the LABEL?

code for setting default value using label string :

$("myAutoCom").autocomplete("search", "someLabel");
var menu = $("myAutoCom").autocomplete("widget");
$(menu[0].children[0]).click();

i have the value,not the label. how can i set selected item depending on value? thanks in advance

2
  • I am not sure if it's possible to do what you wan't. But there might be workaround: if you have object containing all the values, you can set the default autocomplete widget value, by passing label accessed by it's value from all values object, something like this: $("myAutoCom").val(allvaluesobject[label_value_key]); Commented Nov 30, 2014 at 10:39
  • Thank u so much! i did as you said. The source of my autocomplete is a two-dimensional array of labels and values,that array is kept in a global variable, so i just searched that array for corresponding label and used it as a default value for my autocomplete Commented Dec 8, 2014 at 13:52

1 Answer 1

1

since the source of my autocomplete is an array that contains all label-value pairs, and since i keep that array in a global variable, i just did the following:

searched THAT array for the given value and returned the corresponding label, then used that label to initialize the autocomplete using the code mentioned in the question.

thanks to @sepikas-antanas

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

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.