Reputation: 25
I just started using jquery (and autocomplete plugin) and all working ok
heres my scenario I have a span element which I updates when user chooses one of the list values from autocomplete and it updates the input element at the same time. I dont want the autocomplete input element to be updated - I want to keep it with what user entered into it.
thanks in advance
regards
pvee
Upvotes: 1
Views: 1967
Reputation: 126072
Assuming you're using jQueryUI Autocomplete (in the future, please link to the plugin you're using), you can tap into the select
event and use event.preventDefault
to cancel the default behavior of the plugin (which is to replace the input text), and perform some other action:
$("input").autocomplete({
select: function(event, ui) {
event.preventDefault(); // cancel the default behavior of selecting an option
$("#update-me").text(ui.item.label); // update the span with the selected option's label.
}
});
Example: http://jsfiddle.net/5jWkL/
Hope that helps.
Upvotes: 4