i have this jQuery code:
$(".autocomplete").autocomplete('url',{
extraParams: {country: function(){
var id = $(this).attr("id"); // not working
var country = id.replace("uni", "country");
var country_id = $("#"+country).val();
return country_id;
}}
}).result(function(event, item) {
// getNames(item);
});
As I will have several, ajax loaded forms with autocomplete fields, i need for each of them to send appropriate additional parameters from the respective form to the server.
I was trying to achieve this by getting the id of the input field and using it to get to the id of the country field which will hold the necessary parameter. The id's would be in the appropriate format to allow for this. Something like:
uni_1, country_1; uni_2; country_2
uni being the autocomplete field, and country the additional parameter.
I have realised that $(this).attr("id") will not work inside the autocomplete, as it would with simple jQuery events, and I have not found a way of doing this. I tried using the toSource method to see the autocomplete object, but it seems that it does not hold the field id.
So if anyone has an idea how this could be done, please share.
Thank you very much in advance. Ivan
You can try
$(".autocomplete").each(function() {
var id = $(this).attr("id");
$(this).autocomplete('url',{
extraParams: {country: function(){
var country = id.replace("uni", "country");
var country_id = $("#"+country).val();
return country_id;
}}
}).result(function(event, item) {
// getNames(item);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With