0
I did a city search using Javascript.
There is a text field in which the user type the city name. And as he’s typing the letters, the respective cities that start with that letter appear in a ul > li
below the field for the user to click.
You can use the down and up arrow keys to navigate between cities and when the focus is on the li
tighten enter to select the city ?
JS
if(str != ''){
box_div.show();
box_ul.html('');
$.each(data, function(i, val){
box_ul.append("<li id='"+val.id+"'>"+val.cidade+", "+val.estado+"</li>");
});
}
var linhas = $('div.resultados-cidades > ul > li');
var cont = linhas.length;
if(40 == event.keyCode )
active = active >= (cont - 1) ? 0 : active + 1;
else if(38 == event.keyCode )
active = ( active <= 0 ) ? cont - 1 : active - 1;
var a = linhas.removeClass('hover').eq(active).addClass('hover');
In this function he only navigates between the first and the last.
You can mount html to make it easier to understand ?
– Gabriel Rodrigues
It has several autocomplete plugins, you want to do "in the nail", that’s it?
– Renan Gomes
I want to do nail, don’t need a plugin for this...
– Diego Souza
So ta. I was going to recommend
<datalist>
but the support is limited. If you write your own autocomplete, put as answer.– Renan Gomes
My autocomplete is already ready, but it’s not the problem. The problem is my arrow navigation.
– Diego Souza