Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5945809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:44:01+00:00 2026-05-22T16:44:01+00:00

I am using this auto complete library: http://jqueryui.com/demos/autocomplete/#multiple-remote I was wondering if anyone knows

  • 0

I am using this auto complete library: http://jqueryui.com/demos/autocomplete/#multiple-remote

I was wondering if anyone knows how trigger the auto search without typing anything in the text box. i.e. if we want to display the list on a button click event.
the “search” method seems to be doing that. But I cant get it working.

Please note that the data of the auto suggest comes from a web service. If user types something in the text box the suggestion changes accordingly. i.e. the typed data goes to the service and brings back the suggestion.
The input is of “Name, Location” form. As a result for different parts of the input different types of suggestions are displayed.

Codes:

UI:

<div class="ui-widget">
    <label for="birds">Birds: </label>
    <input id="birds" size="50" />
</div>

Script:

<script>
    $(function() {
        function split( val ) {
            return val.split( /,\s*/ );
        }
        function extractLast( term ) {
            return split( term ).pop();
        }

        $( "#birds" )               
            .bind( "keydown", function( event ) {
                if ( event.keyCode === $.ui.keyCode.TAB &&
                        $( this ).data( "autocomplete" ).menu.active ) {
                    event.preventDefault();
                }
            })
            .autocomplete({
                source: function( request, response ) {
                    $.getJSON( "search.php", {
                        term: extractLast( request.term )
                    }, response );
                },
                search: function() {
                    var term = extractLast( this.value );
                    if ( term.length < 2 ) {
                        return false;
                    }
                },
                focus: function() {
                    return false;
                },
                select: function( event, ui ) {
                    var terms = split( this.value );
                    terms.pop();
                    terms.push( ui.item.value );
                    terms.push( "" );
                    this.value = terms.join( ", " );
                    return false;
                }
            });
    });
    </script>

If I type anything it sends a request to search.php.
I tried changing the logic “term.length < 2” to “term.length <= 0”. This works but i have to press the space bar. Then an empty space is placed in the text box and is sends the request to the server. But I don’t want to type anything in there.
Hope that helps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:44:02+00:00Added an answer on May 22, 2026 at 4:44 pm

    If you want to trigger the search when a button is clicked, then you have to call the search method. If you want to show all options, call search with the value set to empty string and set the autocomplete widget to accept minLength: 0.

    So in code:

    UI

    <div class="ui-widget">
        <label for="birds">Birds: </label>
        <input id="birds" size="50" />
        <input type="button" id="search-trigger" value="Trigger" />
    </div>
    

    Script

    <script type="text/javascript">
    $(function() {
        function split( val ) {
            return val.split( /,\s*/ );
        }
        function extractLast( term ) {
            return split( term ).pop();
        }
    
        // Button listener that triggs the search event
        $("#search-trigger").click(function(){
            var searchTerm = $( "#birds" ).val();
            $( "#birds" ).autocomplete( "search" , searchTerm);
        });
    
    
        $( "#birds" )               
            .bind( "keydown", function( event ) {
                if ( event.keyCode === $.ui.keyCode.TAB &&
                    $( this ).data( "autocomplete" ).menu.active ) {
                    event.preventDefault();
                }
            })
            .autocomplete({
                source: ["lorem", "ipsum", "dolor"], 
                    /* Commented this out to use dummy data above
                                function( request, response ) {
                    $.getJSON( "search.php", {
                        term: extractLast( request.term )
                    }, response );
                },*/
                search: function() {
                    var term = extractLast( this.value );
    
                              /* What is this check for?
                    if ( term.length < 2 ) {
                        return false;
                    }*/
                },
                focus: function() {
                    return false;
                },
                select: function( event, ui ) {
                    var terms = split( this.value );
                    terms.pop();
                    terms.push( ui.item.value );
                    terms.push( "" );
                    this.value = terms.join( ", " );
                    return false;
                },
                //Added for "show all" support
                minLength: 0
            });
    });
    </script>
    

    Is this the behavior you are looking for?

    Ref: http://jqueryui.com/demos/autocomplete/#method-search

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery auto-complete. I have download this script from http://code.google.com/p/jquery-autocomplete/ . I
I'm using the autocombox from the jQuery UI library (http://jqueryui.com/demos/autocomplete/#combobox). The combobox is replacing
I'm now using http://jqueryui.com/demos/autocomplete/ based on some previous recommendations and it's working well for
hi i am using Ajax AutoComplete for jQuery library http://www.devbridge.com/projects/autocomplete/jquery/ there are 2 demos
I'm using a Facebook-like autocomplete jquery library found at: http://otisbean.com/dropbox/jquery.tokeninput.js In my own html
I found this plugin: http://vim.wikia.com/wiki/Find_files_in_subdirectories to be really useful to find a file(s) using
I have auto complete for a JCombobox working by following this article: http://today.java.net/pub/a/today/2007/07/19/adding-auto-completion-to-swing-comboboxes.html I
I'm using jQuery AutoComplete, and I have an auto-complete search box to search for
Note: In this question I'm using the term autocomplete (or iterative search) to refer
I followed the directions in this post: how can we integrate jquery autocomplete using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.