Clear field field after selection for jQuery user interface autocomplete

We use jQuery UI autocomplete, and I am having problems clearing the text field containing the search query after the query is completed. Here is our jQuery code:

$(document).ready(function () { $("form#search input#term").autocomplete({ source: '<%= Url.Action("Display", "Search") %>', delay: 200, minLength: 3, parse: function (data) { var array = new Array(); for (var i = 0; i < data.length; i++) { array[array.length] = { data: data[i], value: data[i], result: data[i].link }; } return array; }, select: function (event, ui) { window.location.href = ui.item.value; $(this).val() = ""; return false; } }); }); 

This code works fine in Firefox, but IE 8 throws an exception and gives a dialog asking if I want to use IE Script Debugger. I saw this post: Clear field field after selection for jQuery UI Autocomplete autocomplete , which says that the solution to the problem is to return false from the jQuery select function, but it didn Help. Anyone have any suggestions on how to fix this?

+6
jquery jquery-ui autocomplete
source share
5 answers

The only way I found to fix this problem was to use the old jQuery 1.4.1 library along with the new jQuery UI dll, version 1.8.11, I think that there is only a jQuery dll after version 1.4.1 that causes this problem. If so, perhaps a future version will fix it.

+1
source share

Using jQuery 1.5.1 and jQuery-ui 1.8.10, the following works for me:

 select: function (event, ui) { event.preventDefault() // <=== window.location.href = ui.item.value; $(this).val(''); } 
+10
source share
 $(this).val(''); 

instead

 $(this).val() = ""; 
+2
source share

it works for me ...

 jQuery('.SELECETOR'). autocomplete({ .... .... }).on( "autocompleteselect", function( event, ui ) { jQuery(this).val(''); }); 
0
source share

This works for me:

 jQuery('.SELECTOR'). autocomplete({ // Code }).on( "autocompleteselect", function( event, ui ) { jQuery(this).val(''); }); 
0
source share

All Articles