I use this automatic full library: http://jqueryui.com/demos/autocomplete/#multiple-remote
I was wondering if anyone knows how to run an automatic search without typing anything in the text box. that is, if we want to display the list in the button click event. this seems to be a "search" method. But I canโt make it work.
Please note that auto offer data comes from a web service. If the user enters something into the text box, the sentence changes accordingly. those. The entered data goes to the service and returns the offer. The entry has the form "Name, location". As a result, different types of sentences are displayed for different input parts.
Codes:
interface:
<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 of "term.length <2" to "term.length <= 0". This works, but I have to press the spacebar. Then the empty space is placed in the text box and sends a request to the server. But I do not want to enter anything there. Hope this helps.
source share