I'm trying to create suggested tags, first i take input string while the user is typing, then check for words from a long list of words in an array, if word exists in the first array, check other arrays categories that this word falls into, then append some tag in an input.
First Problem: So far i can only check if a string contains a word, i don't know how to search an array so i can find words in a given string that match words in an array.
Second Probelm
After first word if found on keyup, any other keyup runs the script whereas i want it to wait for another second match.
CODE HERE
$(document).on('keyup','.Post_TextArea',function(){
post_val = $(this).val();
if ($(this).val().length > 5){
var string_g = 'tempo';
var web_array = ['html', 'css', 'JavaScript'];
var music_array = ['tempo', 'blues', 'rhythm'];
if (post_val.toLowerCase().indexOf(string_g) >= 0){
if ($.inArray(string_g, web_array) !== -1){
$('.tags_holder').append('<span class="Tag_Style">Web</span>');
} else if ($.inArray(string_g, music_array) !== -1){
$('.tags_holder').append('<span class="Tag_Style">Music</span>');
}
}
}
})