Your select
callback should look something like this:
select:function(event,ui){
var item=ui.item;
if(item){
$(".nameautoc", $(this).parents('tr')).val(item.name);
}
}
By adding $(this).parents('tr')
as context in the jquery selector (Refer to JQuery docs for more details), you're making sure that only the matching child elements of the parent tr
element are updated, instead of all elements with class nameautoc
in the document.
Optionally, you can also use $(this).parent().parent()
to traverse upto the tr
, instead of using $(this).parents('tr')
. Here's the working fiddle.