J
J
jeston2011-01-13 20:29:32
JavaScript
jeston, 2011-01-13 20:29:32

Programmatically make Jquery UI Combobox autocomplete item selected?

Tell me, please, JQuery experts, because I've been struggling for the third day in fruitless attempts:
1. I use two JQueryUI Autocomplete combobox elements on the page from here jqueryui.com/demos/autocomplete/#combobox
2. after selecting an element in the first combobox, ajax is executed - request, the data arrives safely and I fill the second combobox with them like this:

$.each(obtainedData,function(i,item){
options += "" + item + "";
});
$("#combobox option").remove(); // removed the old list that might be there
$("#combobox").append(options).combobox();

3. and I want to programmatically select the first element of the newly formed list.
Nothing!!! Zero reaction to code like this:

$("#combobox :first").attr("selected", "selected");

nor for various variations of it, although for a regular HTML select it works with a bang.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nodge, 2011-01-13
@Nodge

When creating a combobox() , an input is created to enter and display the value. Try like this:

var first = $("#combobox :first");
first.attr("selected", "selected");
$("input").val(first.val());

Just replace the "input" selector with the one you need for your code.

F
Fr3nzy, 2011-01-13
@Fr3nzy

I think .change() and/or .focus() events can help you

J
jeston, 2011-01-13
@jeston

I accept any fresh idea, just be more specific, please.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question