<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><title>jQuery UI Autocomplete - Multiple, remote</title><linkrel="stylesheet"href="../../themes/base/jquery.ui.all.css"><scriptsrc="../../jquery-1.6.2.js"></script><scriptsrc="../../ui/jquery.ui.core.js"></script><scriptsrc="../../ui/jquery.ui.widget.js"></script><scriptsrc="../../ui/jquery.ui.position.js"></script><scriptsrc="../../ui/jquery.ui.menu.js"></script><scriptsrc="../../ui/jquery.ui.autocomplete.js"></script><linkrel="stylesheet"href="../demos.css"><style>.ui-autocomplete-loading{background:whiteurl('images/ui-anim_basic_16x16.gif')rightcenterno-repeat;}</style><script>$(function(){functionsplit(val){returnval.split(/,\s*/);}functionextractLast(term){returnsplit(term).pop();}$("#birds")// don't navigate away from the field on tab when selecting an item.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(){// custom minLengthvarterm=extractLast(this.value);if(term.length<2){returnfalse;}},focus:function(){// prevent value inserted on focusreturnfalse;},select:function(event,ui){varterms=split(this.value);// remove the current inputterms.pop();// add the selected itemterms.push(ui.item.value);// add placeholder to get the comma-and-space at the endterms.push("");this.value=terms.join(", ");returnfalse;}});});</script></head><body><divclass="demo"><divclass="ui-widget"><labelfor="birds">Birds: </label><inputid="birds"size="50"></div></div><!-- End demo --><divclass="demo-description"><p>Usage: Enter at least two characters to get bird name suggestions. Select a value to continue adding more names.</p><p>This is an example showing how to use the source-option along with some events to enable autocompleting multiple values into a single field.</p></div><!-- End demo-description --></body></html>