0
I have the following autocomplete that works in the first input, when completing it fills in the 2nd input.
The problem is that if I delete the tag <p>
it doesn’t work. Someone can tell me why?
Follows the code:
$().ready(function() {
$("#singleBirdRemote").autocomplete("search.php", {
width: 260,
selectFirst: false
});
$("#singleBirdRemote").result(function(event, data) {
if (data)
$(this).parent().next().find("#xx").val(data[0]);
});
});
<p>
<input type="text" id="singleBirdRemote">
</p>
<p>
<input name="asdad" id="xx">
</p>
Good in its form did not work, I found a solution like: $(this). Parent(). find("input[@name=value]"). val(data[3]); what you think?
– Hugo Borges
How did you apply the solution? Apparently there were changes in the code, since there is a name in the input and now you index date by 3, not by zero, IE, could apply $("#xx"). val(date[3]);
– Danilo Gomes
The problem with the solution you used is that you keep using the reference by Parent! This should be avoided when possible! Otherwise your code becomes too dependent on the html hierarchy!
– Danilo Gomes
thus: https://jsfiddle.net/6gt2z1z8/
– Hugo Borges
Just try $("input[name=b]"). val(data[3]); Have everything to work without relying on the hierarchy!
– Danilo Gomes
perfect, works 100%
– Hugo Borges