Display Partial Array Value Matches From User Input
I have a jQuery array with a bunch of values. I want a user to be able to type into an input and have any partial matches to anything within my array display on the screen. So far
Solution 1:
something like this should work for you:
SUBSTRING SEARCH
for(var x = 0; x < ingredients.length; x++){
if(ingredients[x].indexOf($("#ingredient-search").val()) > -1)
$(".append").append(ingredients[x]+"<br>");
}
FIDDLE http://jsfiddle.net/BeNdErR/f5use/3/
'STARTING WITH' SEARCH
for(var x = 0; x < ingredients.length; x++){
if(ingredients[x].indexOf($("#ingredient-search").val()) == 0)
$(".append").append(ingredients[x]+"<br>");
}
FIDDLE http://jsfiddle.net/BeNdErR/f5use/5/
CASE INSENSITIVE SEARCH
for(var x = 0; x < ingredients.length; x++){
if(ingredients[x].indexOf(($("#ingredient-search").val()).toLowerCase()) == 0)
$(".append").append(ingredients[x]+"<br>");
}
FIDDLE http://jsfiddle.net/BeNdErR/f5use/6/
here is indexOf
docs: indexOf()
Post a Comment for "Display Partial Array Value Matches From User Input"