0
I have the following autocomplete defined in HTML
HTML
<label class="input">
<input type="text" list="list" id="entidade" placeholder="Cliente" onblur="dadosCliente ( )">
<datalist id="list">
@for(entidade <- entidades) {
<option name="ent" id="@entidade.getId()" value="@entidade.getNome()">@entidade.getNome()</option>
}
</datalist> </label>
The autocomplete is working well, BD data is being searched. How can I now at jQUERY
fetch the ID of the selected element?
I’ve tried this: $("option[name=ent] :selected").attr('id');
but returns Undefined. Any Suggestion?
Continue 'Undefined' :s if I take ':Selected' returns me always the value 2, I don’t know why
– Hugo Machado
see the edition of my reply
– lucasDotCom
thus appears: Uncaught Typeerror: Cannot read Property 'toLowerCase' of Undefined
– Hugo Machado
what’s in the data function? It is used more than once?
– lucasDotCom
Not only is it used by losing the focus of that field, nothing else, and right now I’m just trying to get the id of the item I chose by autocomplete. var name = $('#entity'). val(); which returns the name I selected for this field.
– Hugo Machado
remember to put the function inside
$(document).ready()
Or on onblur pass this.value in the function, and in the receive function as a variable– lucasDotCom
Edited’s solution2 And it’s working great. Thank you very much
– Hugo Machado