The method in which I add a new input field, written below the code.
function addInput(){ // Code to append new input filed next to existing one. $("table").find('input[id=clientId]:last').autocomplete({ source: function (request, response) { var id = this.element[0].id; var val = $("#"+id).val(); $.ajax({ type : 'Get', url: 'getName.html?name=' + val, success: function(data) { var id = $(this).attr('id'); $(this).removeClass('ui-autocomplete-loading'); response(data); }, error: function(data) { $('#'+id).removeClass('ui-autocomplete-loading'); } }); }, minLength: 3 }); }
And some where in other js that will be used for all other (static) input fields under the code are used.
jQuery("input.searchInput").autocomplete({ source: function (request, response) { var id = this.element[0].id; var val = $("#"+id).val(); $.ajax({ type : 'Get', url: 'getName.html?name=' + val, success: function(data) { var id = $(this).attr('id'); $(this).removeClass('ui-autocomplete-loading'); response(data); }, error: function(data) { $('#'+id).removeClass('ui-autocomplete-loading'); } }); }, minLength: 3 });
Note. - For any autocomplete requests in dynamically added inputs, the autocomplete function addInput () will be called.
Thanks @Salman and this post Enabling jQuery autocomplete in dynamically generated input fields to give me an idea.
Jaikrat Oct 30 '15 at 8:26 2015-10-30 08:26
source share