I want to find any match array in input value:
var vals = new Array('stackoverflow', 'google', 'yahoo');
var val = $('#txtAddress').val();
if ($.inArray(val, vals) != -1) {
alert('yep');
} else {
alert('nope');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="txtAddress" type="text" value="google is better" maxlength="100" id="txtAddress">
but it's not working, I want tp find any match array in value, for example value is google is better and array is google but it won't find google in this value, only works when value is google and array is google like this:
var vals = new Array('stackoverflow', 'google', 'yahoo');
var val = $('#txtAddress').val();
if ($.inArray(val, vals) != -1) {
alert('yep');
} else {
alert('nope');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="txtAddress" type="text" value="google" maxlength="100" id="txtAddress">
so, any solution to find any match array in this value?
Update: I also tried this way but not working too:
var vals = new Array('stackoverflow','google','yahoo');
var val = $('#txtAddress').val();
for (var i = 0; i < vals.length; i++) {
if (vals[i] === val) {
alert('Value exist');
} else {
alert('Value does not exist');
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="txtAddress" type="text" value="google is better" maxlength="100" id="txtAddress">
And can I alert that matched terms?