Reputation: 51
I have the following HTML:
<input name="data[Content][0][name]" type="text" class="content_name_1" id="content_name" >
<input name="data[Content][1][name]" type="text" class="content_name_2" id="content_name" >
........
<input name="data[Content][n][name]" type="text" class="content_name_n" id="content_name" >
And the following jQuery-Code:
$('input[name="data[Content][0][name]"]').autocomplete({
minLength: 0,
source: function(request, response){
$.ajax({
url: '/contents/ajax_search/' + request.term,
dataType: 'json',
success: function(data){
response(data);
}
});
}
});
I create dynamicly HTML input fields and I want to link them with the autocomplete function, but i just can do this with one of them. How can I solve this problem?
Upvotes: 0
Views: 691
Reputation: 13525
First method is to use multiple selectors,
$('input[name="data[Content][0][name]"], input[name="data[Content][1][name], input[name="data[Content][2][name]"]"] ').autocomplete({
});
Second method is to add class="common"
in all your html boxes and use the class name as selector
$('.common').autocomplete({
});
Upvotes: 1