autocomplete - JQuery - Get calling element id -


problem

in source function of autocomplete want selector's id. there way can travese through call stack , this? jquery have level of abstraction?

why?

i have multiple autocompletes on page , each 1 handled differently on server side. have use function source. otherwise have used url + data: long time ago =p

jquery version

jquery-1.9.1

research

of course i've been on this: jquery api

how element id dynamically generated form elements jquery?

a lot of these attempts didn't think work, right i'm @ point of trial , error.

$(this).attr('id'); - undefined

caller function name

i though i'd try caller functions name, , it...doesn't seem output anything.

appending source function (this absurd!!! appending text function?! 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 i'm testing see ids.     $.post(ajaxpageautocomplete, { searchterm: request.term, field: 'inpdvehmk'}, //i want field dynamic depending on 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);             }         }     ); } 

i'm embarrassed how long took me figure out.

use line in source function id of autocomplete.

$(this.element).prop("id") 

since autocomplete jquery widget, this object refers widget instance. element, need go through it's element property.

jsfiddle

to fair, isn't documented unless creating widgets using widget factory.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -