Reputation: 35
after set value for hidden input with jQuery UI autocomplete
$( "#PName" ).autocomplete({
search: function(event, ui) {
$("#PLoading").show();
},
source: "Script_URL",
minLength: 2,
select: function( event, ui ) {
$("#PLoading").hide();
$("#PName").val(ui.item.value);
$("#PID").val(ui.item.id);
}
});
<input type="hidden" id="PID" name="PID" value="0" />
for send new value from hidden input to other url with autocomplete , send 0 value
0 value is hidden input default value , ( for test, i changed default value to 90 , but again send default value ( 90 ) )
$("#CName").autocomplete({
search: function(event, ui) {
$("#CLoading").show();
alert ($("#PID").val()); // it's worked, and alert new value , from hidden input
},
source: "Script_URL/"+$("#PID").val(), /// but it's not worked , does not send new value from hidden input
minLength: 2,
select: function( event, ui ) {
$("#CLoading").hide();
$( "#CName" ).val(ui.item.value);
$( "#CID" ).val(ui.item.id);
}
});
Upvotes: 4
Views: 993
Reputation: 126042
Your code is only going to read the value of the hidden input once, when the widget is initialized. If you want to update the source URL every time, you'll have to supply a function to the source
parameter and make the AJAX request yourself:
$( "#PName" ).autocomplete({
search: function(event, ui) {
$("#PLoading").show();
},
source: function () {
$.ajax({
url: "Script_URL/" + $("#PID").val(),
data: request,
dataType: "json",
success: function (data) {
response(data);
},
error: function () {
response([]);
}
});
},
minLength: 2,
select: function( event, ui ) {
$("#PLoading").hide();
$("#PName").val(ui.item.value);
$("#PID").val(ui.item.id);
}
});
Upvotes: 2