У меня есть несколько полей ввода:
<input type="text" name="product_1" value="" id="input-pricebyproduct"/>product-1</input>
<input type="text" name="product_2" value="" id="input-pricebyproduct"/>product-2</input>
<input type="text" name="product_3" value="" id="input-pricebyproduct"/>product-3</input>
Как передать переменные по атрибуту имени в autocomplete ()?
<script type="text/javascript"><!--
$('input[name="product"]').autocomplete({
source: function(request, response) {
$.ajax({
url: 'index.php?route=extension/module/price_autoupdate/autocomplete&user_token={{ user_token }}&filter_product=' + encodeURIComponent(request),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
label: item['name'],
value: item['product_id']
}
}));
}
});
},
select: function(item) {
$('input[name=\'product\']').val('');
$('#input-product' + item['value']).remove();
$('#input-product').append('<div id="input-product' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="module_price_autoupdate_product[]" value="' + item['value'] + '" /></div>');
}
});
$('#input-product').delegate('.fa-minus-circle', 'click', function() {
$(this).parent().remove();
});
//--></script>
Я застрял на этом и не могу найти решение...
Я пробовал это:
var key = $("#input-pricebyproduct").attr('name');
$('input[name=" + key + "]').autocomplete({
//the rest stuff
});
Но, кажется, что-то не хватает, и это решение не работает ... Я могу получить атрибут только с первого ввода.Как это решить?