Problem
In the source function of the autocomplete I want to get the selector's ID. Is there a way I can travese through the call stack and get this? Does JQuery
have this level of abstraction?
Why?
I will have multiple autocompletes on the page and each one will be handled differently on the server side. I have to use another function for the source. Otherwise I would have used a URL + data: a long time ago =p
JQuery Version
jquery-1.9.1
Research
Of course I've been all over this: JQuery API
How to get element Id from dynamically generated form elements with jquery?
A lot of these attempts I didn't think would work, but right now I'm at the point of trial and error.
$(this).attr('id'); - undefined
I though I'd try to get the caller functions name, and do something with it...doesn't seem to output anything.
Appending to the source function (this is absurd!!! Appending text to a function?! Really I'm desperate...)
$("#inPdVehMk").autocomplete({
source: autoCompletePost + "field="+$(this).attr('id'),
minLength: 2,
select: function(event, ui){
alert(ui.label1);
alert("value= " + ui.item.value + " id= "+ ui.item.id);
}
});
Auto Complete Setup
$("#inPdVehMk").autocomplete({
source: autoCompletePost,
minLength: 2,
select: function(event, ui){
alert(ui.label1);
alert("value= " + ui.item.value + " id= "+ ui.item.id);
}
});
Source function
function autoCompletePost(request, response){
//alert($(this).attr('id')); //this is where I'm testing to see the ids.
$.post(AjaxPageAutoComplete, { searchTerm: request.term, field: 'inPdVehMk'}, //I want field to be dynamic depending on the calling selector.
function(data) {
var splitData = data.split("%");
var json = jQuery.parseJSON(splitData[1].toString());
if(data.search('autoCompleteError') !== -1 || data.length < 1){
DialogBox('Div_ErrorMessage^Open^autoCompleteError');
}else{
response(json);
}
}
);
}