Skip to content Skip to sidebar Skip to footer

How Can I Create An Autocomplete Box For The Tag Input?

Here is my code: As you see, I'm trying to create a tag attachment box for a post. Now I need to create an autocomplete box for tags. I can do that by jQuery UI, but I don't want

Solution 1:

Try this:

var tags = ["PHP", "MySQL", "HTML", "CSS", "C", "SQL", "JavaScript"];

var searchTerm = 'SQ';

var matches = tags.filter(function(tag) {
    return tag.toLowerCase().indexOf(searchTerm.toLowerCase()) >= 0;
});

console.log(matches);

Solution 2:

an easy way to do this, is with Array.filter

you would need a polyfill to support IE browsers

var tags = ["PHP", "MySQL", "HTML", "CSS", "C", "SQL", "JavaScript"];
function autocomplete(query) {
  var re = new RegExp(query,"gi");
  return tags.filter(function(tag){
    return re.exec(tag) 
  })
}

autocomplete('h')

Post a Comment for "How Can I Create An Autocomplete Box For The Tag Input?"