Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an Ajax.Autocompleter perform a request without typing?

I'm using scriptaculous's Ajax.Autocompleter for a search with different filters.

http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter

The filters are requiring me to pass data into the autocompleter dynamically, which I've successfully learned to do from the following link.

http://www.simpltry.com/2007/01/30/ajaxautocompleter-dynamic-parameters/

Now, I have multiple filters and one search box. How do I get the autocompleter to make the request without typing into the input, but by clicking a new filter?

Here's a use case to clarify. The page loads, there are multiple filters (just links with onclicks), and one input field with the autocompleter attached. I type a query and the autocompleter request is performed. Then, I click on a different filter, and I'd like another request to be performed with the same query, but different filter.

Or more succinctly, how do I make the autocompleter perform the request when I want, instead of depending on typing to trigger it?


1 Answers

I also found that the activate() method worked great. Here is my sample code....

<script type="text/javascript">
    /*<![CDATA[*/

    var autocomp1 = new Ajax.Autocompleter("search", "AjaxResultsListPlaceholder", "ajaxServerSideSearchHandler.php", {
            frequency: 1,
            minChars: 10,
            indicator: "AjaxWorkingPleaseWaitPlaceholder",
            } );


    /*]]>*/
</script>

<form id="theform">
    <input type="text" id="search" name="search" value="" />
    <input type="button" id="btn_search" name="btn_search" value="Search" onclick="autocomp1.activate();" />
    <div id="AjaxWorkingPleaseWaitPlaceholder" style="display: none; border: 1px solid #ffaaaa;">
    </div>
    <div id="AjaxResultsListPlaceholder" style="display: none;; border: 1px solid #aaffaa;">
    </div>

</form>
like image 66
Lyudmyla Avatar answered Dec 09 '25 11:12

Lyudmyla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!