Why won't #input-myBox clear when I select an item? It seems autocomplete is preventing my .val('') to work so how can I workaround this?
$("#input-myBox").autocomplete({
    source: response,
    minLength: 1,
    select: function(event, ui) {
                var selectedObj = ui.item;
                $("#input-myBox").appendTo(".foo");
                $("#input-myBox").val('');  
    }
});
                event.preventDefault() stops autocomplete setting the field.
select: function (event, ui) {
  event.preventDefault();
  var selectedObj = ui.item;
  $("#input-myBox").appendTo(".foo");
  $("#input-myBox").val('');  
}
                        Also, you can use 'return false;' to stop autocomplete setting the field.
select: function (event, ui) { 
    var selectedObj = ui.item;        
    $("#input-myBox").appendTo(".foo");
    $("#input-myBox").val('');  
    return false;
}
                        If you just want to substitute the selected value for something else:
select: function( event, ui ) {
  ui.item.value = substituteWord(ui.item.value);
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With