ページに動的に作成される入力フィールドがいくつかあります。JQueryでは、値をphpスクリプトに渡してオートコンプリートに入力できるように、入力している値を取得しようとしています。
例えば:
<input id="inventory_location_1">
<input id="inventory_location_2">
<input id="inventory_location_3">
<input id="inventory_location_4">
<input id="inventory_location_5">
<input id="inventory_location_6">
何らかの理由で「inventory_location_1」にテキストを入力している場合、var strValue = $(this).val(); を使用できません。入力しているボックスのテキストを取得します。Jquery はエラーをスローします。
これが私の完全な Jquery スクリプトです。
$(function() {
$('input[id^=inventory_location_]').autocomplete({
source: function( request, response ) {
$("#progressBar").show();
var strValue = $(this).val();
alert(asdf);
$.ajax({
url: '{{ path('inventory_id_via_ajax_array') }}',
dataType: "json",
data: {
featureClass: "P",
style: "full",
maxRows: 12,
value: strValue
},
success: function( data ) {
if(data.responseCount <= 0){
}
response( $.map( data.responseData, function( item ) {
return {
label: item.name,
name: item.name,
value: item.name,
id: item.id
}
}));
$("#progressBar").hide();
}
});
},
minLength: 2,
select: function( event, ui ) {
$("#progressBar").hide();
$(this).val(ui.item.label);
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
});
どうすればいいのかわからないので、考えられることはすべてやった。また、私のスクリプトに正しくない点が他にもある場合は、アドバイスしてください。ご協力いただきありがとうございます!!!