Autocomplete on dynamically added textboxes
i have a textbox on which autocomplete works perfectly.Below is my jquery code which is used to autocomplete
$.widget("custom.catcomplete", $.ui.autocomplete, {
_renderMenu : function(ul, items) {
var self = this;
$.each(items, function(index, item) {
self._renderItem(ul, item);
});
}
});
var autocmp= $("#countryOfOrigin").catcomplete({
delay : 0,
source : "/pages/getCountry.jsp",
select : function(event, ui) {
$('#originCountryId').val(ui.item.id);
}
});
I am adding textboxes dynamically..I want to add this autocomplete on these dynamilcally added textboxes.
I am using below javascript to generate these new textboxes.
$("#addNewAttach").click(function() {
var counter=1;
var input = $("<input type='text' name='countryOfOrigin["+counter+"]' />");
var row = $('<tr />').append( $('<td />').append(input) );
$("#htstable > tbody").append(row);
counter++;
var data = autocmp;
alert(data.val);
input.find('input').autocomplete(data.val);
});
This is adding textboxes dynamically but the autocomplete on these textboxes is not invoking.
Please guide me what i am missing.