Skip to content

Instantly share code, notes, and snippets.

@adonaldson
Created August 27, 2010 12:25
Show Gist options
  • Save adonaldson/553264 to your computer and use it in GitHub Desktop.
Save adonaldson/553264 to your computer and use it in GitHub Desktop.
// From http://stackoverflow.com/questions/3583989/jquery-autocomplete-pass-targeted-element-attribute-as-an-extra-parameter
$("#autocomplete input").each(function() {
var that = this;
$(that).autocomplete({
source: function(request, response) {
$.ajax({
url: "search.php",
dataType: "json",
data: {
term: extractLast(request.term),
extra_param: $(that).attr('id')
},
success: function(data) {
response($.map(data, function(item) {
return {
label: item.label,
value: item.name
}
}))
}
})
},
});
});
@adonaldson
Copy link
Author

Theres probably more scope to make it more efficient, but breaking it into an each first allows you to set 'that'

@plindsay
Copy link

Yay! That's worked - cheers mate :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment