$(function() {
var availableTags = [
"Action Script",
"Apple Script",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"Cold Fusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"Java Script",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$( "#tags" )
// 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( "ui-autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 1,
source: function( request, response ) {
//check if the request string starts with a space
if(request.term===' ')
{
response([{value: "Enter Some text to search"}]);
return false;
}
// delegate back to autocomplete, but extract the last term
response( $.ui.autocomplete.filter(
availableTags, extractLast( request.term ) ) );
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
});
});
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<div class="ui-widget">
<label for="tags">Tag programming languages: </label>
<input id="tags" size="50"></input>
</div>
<div style="height:2px; background-color:gray; margin-top:100px;"></div>
<iframe id="iframe1" src="http://jqfaq.com/AdPage.html" style="width:100%;border:none;" />
External resources loaded into this fiddle: