I need help with jquery autocomplete. The autocomplete by itself works fine, but I need to fill a value in another input field depending on the value of the first input.
I created https://jsfiddle.net/peh9c20a/ to show this problem.
I have a form with three rows, each row has two input fields. Autocomplete is implemented on the first column of inputs.
When selecting a value from the autocomplete (first column), the desired behavior is to fill the input field next to it with a random number. I am unfortunately able to fill all the inputs with a number, not only the input in the same row.
To describe this problem with the text is a little bit complicated, but I hope that the fiddle will help to understand it.
The form is made dynamically with clone() function, I can´t use different ID attributes for each input.
$('.item-name').autocomplete({
lookup:sourceData,
onSelect: function (suggestion) {
var number = Math.floor(Math.random()*100);
$(this).closest($(".item-id").val(number)); //THIS ROW HAS TO BE MODIFIED
}
});