If using an additional library is not a problem for you, Bootstrap solves your problem with a little jQuery help.
I have prepared a simple JSFiddle for you, where you can see it in action:
http://jsfiddle.net/sgmonda/Tjbys/8/
What I did was prepare text input and a <ul> list where your selected tags will be displayed. Bootstrap allows autocomplete when writing to the input, so you should disable autocomplete by default:
<input type="text" id="tags" autocomplete="off" /> <ul id="selected-tags"></ul>
Then you just need to add some jQuery lines so that Bootstrap will autocomplete your input and add the selected tags to your <ul> list:
$('#tags').typeahead({ source: ['elem1', 'elem2', 'elem3', 'otherElem', 'oneMore'], updater: function (item) { $('#selected-tags').append('<li>' + item + '</li>'); } });
Whenever you want, you can read the list to find out which items have been selected by the user.
var selectedTags = []; $('#selected-tags').each(function(){ selectedTags.push($(this).text()); });
EDIT
If you want to avoid duplication of tags and add the ability to remove them:
http://jsfiddle.net/sgmonda/JMepQ/3/
source share