Search code examples
javascriptautocompletescriptaculous

Scriptaculous Autocomplete: Returns a List of Links, Want to Have Link Clicked Instead of Autofilling the Input Field


I am working with scriptaculous' autocomplete. I am returning an unordered list but each element is a link. For example,

<ul>
    <li><a href="link1">Link 1</a></li>
    <li><a href="link2">Link 2</a></li>
</ul>

If you scroll down the list using the arrow keys and hit enter, Autocomplete will only grab the text instead of activating the link, as it is designed to do. What I want, is for autocomplete to go to the new page. Is there any way to do this, and I have no problem editing the scriptaculous code to do so.


Solution

  • Use the afterUpdateElement, as in the example on http://madrobby.github.com/scriptaculous/ajax-autocompleter/

      new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "/url/on/server", {
        afterUpdateElement : function(text, li){
           document.location.href = "http://mypage.com/page/" + li.id;
        }
      });