Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  162] [ 5]  / answers: 1 / hits: 61863  / 13 Years ago, wed, june 1, 2011, 12:00:00

I am using jquery autocomplete combobox
and everything is ok. But I also want to set specific value through JavaScript like $(#value).val(somevalue) and it set to select element, but no changes in input element with autocomplete.



Of course, I can select this input and set value directly, but is it some other ways to do that? I try set bind to this.element like this.element.bind(change, function(){alert(1)}) but it was no effects. And I don't know why.



Edit



I found a workaround for this case. But I don't like it. I have added the following code to _create function for ui.combobox



this.element.bind(change, function() {  
input.val( $(select).find(option:selected).text());
});


And when I need to change the value I can use $(#selector).val(specificvalue).trigger(change);


More From » jquery

 Answers
15

Is this demo what you are looking for?



The link sets the value of the jQuery UI autocomplete to Java. The focus is left on the input so that the normal keyboard events can be used to navigate the options.



Edit: How about adding another function to the combobox like this:



autocomplete : function(value) {
this.element.val(value);
this.input.val(value);
}


and calling it with the value you want to set:



$('#combobox').combobox('autocomplete', 'Java'); 


Updated demo



I cannot find any available existing function to do what you want, but this seems to work nicely for me. Hope it is closer to the behaviour you require.


[#91936] Tuesday, May 31, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iyannae

Total Points: 147
Total Questions: 88
Total Answers: 120

Location: Japan
Member since Sat, Jun 6, 2020
4 Years ago
;