the html section looks like:

<div id="suggestions" style="display: none;">
        <div  id="autoSuggestionsList">
                        <li> Hi1</li>
                        <li> Hi2</li>
                        <li> Hi3</li>
        </div>
</div>



and then I added Sime Vidas code:
 $(document).ready(function() {

        $("#autoSuggestionsList :first").addClass("selected");
        $().keydown(function(e) {
            var $item = $(".selected").removeClass("selected");
             if (e.keyCode === 40) { // bottom
                  $item.next().is("li");
                  $item.next().addClass("selected");
                  alert($item[0].innerHTML);
             }

              });
    });

when i load the page and press the down arrow, everythings works fine:
"Hi1", "Hi2", "Hi3".

But then comes the problem: typing something inside a textfield the
function "lookup()" is calles (see my first post). this function shows
the values given back by php:

$('#suggestions').show();
$('#autoSuggestionsList').html(data);

when the suggestion box is displayed and filled with values in the
autoSuggestionList, my old values  <li> Hi1</li>, <li> Hi2</li>, <li>
Hi3</li> disappear (but thats still okay..) and
pressing the down key leads to nothing. No alert anymore. It seems,
that he doesnt find anything inside the box "autoSuggestionsList"...

anybody can tell me how i can access the values in the box?



regards
m.sirin


On 9 Jan., 18:59, "m.sirin" <m.siri...@googlemail.com> wrote:
> Okay, thank you.
>
> But I dont know how to iterate through the values of
> #autoSuggestionsList. They are like
>  <li a href="#" onclick="myfunction();"> Hello1 </li>
>  <li a href="#" onclick="myfunction();"> Hello2 </li>
>
> Like this?   if (#autoSuggestionsList.next().is("li")) {
>                      '#autoSuggestionsList.next().addClass
> ("selected");
>                      ...
>                  }
>
> In the example you posted one can see:
>  $(document).ready(function() {
>
> That means the key event would affect the whole homepage? How to
> activate this up/down arrow function only for the suggestion list ?
>
> On 9 Jan., 18:32, Šime Vidas <sime.vi...@gmail.com> wrote:
>
> > I forgot to mention: don't get freaked out by the code... basically
> > what you need is:
>
> >         $().keydown(function(e) {
>
> >             if (e.keyCode === 40) {
>
> >                     // down cursor key was pressed
>
> >             } else if (e.keyCode === 38) {
>
> >                     // up cursor key was pressed
>
> >             }
>
> >         });

Reply via email to