I am using a jQuery autocomplete widget on a text input to replace a dropdown list. The prompt displays when a user clicks on a text field. My solution works fine in FireFox, but works with a slight glitch in Internet Explorer 8. In Internet Explorer, when an item is selected from a sentence that drops down, the list of suggestions disappears and then reappears for a short time. I do not know how to prevent this.
I use: (jquery) jquery-1.6.4.min.js (jquery UI) jquery-ui-1.8.16.custom.min.js
Code below
<input type="text" style="width:200px;" id="txtPosTypeS" value="" />
var RegTempList = [
{ label: "Auxiliary Monthly Trust", value: 1000},
{ label: "Auxiliary Monthly Operating", value: 1001},
{ label: "Auxiliary Hourly Trust", value: 1002},
{ label: "Auxiliary Hourly Operating", value: 1003}]
$().ready(function() {
$('#txtPosTypeS').autocomplete({
minLength: 0,
source: RegTempList,
delay: 0,
focus: function( event, ui ) {
$(this).val( ui.item.label );
return false;
},
select: function( event, ui ) {
$(this).blur();
$(this).val( ui.item.label );
return false;
},
change: function (event, ui) {
if ($(".ui-autocomplete li:textEquals('" + $(this).val() + "')").size() == 0) {
$(this).val('');
$('#hidPositionType').val('');
}
},
close: function(event, ui) {
$(this).blur();
return false;
}
})
.focus(function(){
$(this).autocomplete('search','');
})
.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + "</a>" )
.appendTo( ul );
}; });
source
share