Say I have the following HTML:
<div class="name">
First: <input type="text" name="firstName" class="firstName">
Last: <input type="text" name="lastName" class="lastName">
</div>
Here's the JS that corresponds to that HTML:
$('.lastName').last().autocomplete({
source: function(request, response) {
var firstName = $('.firstName', $(this).closest('.name'));
var lastName = request.term;
console.log(firstName + ' ' + lastName);
}
});
I'd like to have autocomplete pull the closest .firstName to the .lastName field that the source method is linked to but it's not working.
Superficially it seems like if that's not gonna work that I could attach some sort of unique ID to .lastName but if the only thing I can access is request then it's not like I can simply add a data-whatever attribute to the <input> element.
Any ideas?
Here's my JS Fiddle: https://jsfiddle.net/f86nLrq9/
response(array)in thesourcecallback. What would you use the first name for while trying to select last name?$(this).siblings('.firstname').val()thisis ambiguous. You must use a more specific selector.$(this.element)for proper reference.thisis in relationship to the Instance and not the Element.