I been working a script that will check if the new input 'value/string' is already exist, but so far I cant find the correct/efficient solution.
<input type="text" class="existingKeywords" value="string1, string2, string3">
<input type="text" class="newKeyword" value="">
the value of .newKeyword will defend on user input and once submit button is click, it will check if the newKeyword.val() already exist from .existingKeywords.val(); separated by ','
I tried but returns 'json parse unexpected character'
var arr = JSON.parse("[" + $('.existingKeywords').val() + "]");
var newKey = $('.newKeyword').val();
if( jQuery.inArray (newKey, arr) ){
alert('Found!');
}
Can someone tell me, why its not working or Is there a better approach than this?
Thanks!
Thank you so much guys, the script is now perfectly working. I want to 'Vote Up' everyone's answer but it requires 15 Reputation, and as of this writing I only have 13 reputation. And again gracias everyone.