I have implemented autocomplete function on one input in view correctly now I want to allow users to add more inputs by (add button in js) the problem is newly added inputs are not calling autocomplete function why?
Auto complete function
$(document).ready(function () {
$(".AOI").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Test/SearchAOI",
type: "POST",
dataType: "json",
data: { Prefix: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.AOIName, value: item.AOIName };
}))
}
})
},
messages: {
noResults: '',
results: function (resultsCount) { }
}
});
})
function to enable users to add more inputs
var areaIndex = "b";
$("#addAOI").click(function () {
//create the elements representing the new object, giving them a fake indexer
areaIndex = areaIndex + "b";
$("#AOIFields").append("<td><input type='hidden' name='AOI.Index' value='"+areaIndex+"' style='display:none;' /> <input type='text' class='form-control AOI' name='AOI["+areaIndex+"]' /></td>");
})
part of view
<input type="hidden" name="AOI.Index" value="123"style="display:none"/>
<input type="text" class="form-control AOI" name="AOI[123]" />
</td>
</tr>