Scriptaculous Ajax Autocomplete callback example

December 6, 2014

Image for Scriptaculous Ajax Autocomplete callback example from

Recently, whilst working on an old website at work, I found a need to add additional parameters to a Ajax.autocomplete call The documentation show that this is possible via the callback function but unfortunately there isn't an example provided.

Googling found a page that had an example but unfortunately the page wasn't available. One quick visit to the Internet Archive's wayback machine and the page was found. So, here's how to use the callback function on a Ajax.Autocomplete:

    new Ajax.Autocompleter("searchT", "searchH",
        "/api/autocompleter.php", {
            callback: function(element, entry) {
                return entry + '&format=' + window.currentFormat;
            minChars: 3,
            parameters: 'action=searchReleaseFormat',
            afterUpdateElement: submitAjaxTracklistSearch

This will add the &format= parameter to the default parameters sent by the Autocompleter code.

I hope this helps someone in the future.